Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- deps/exla/cache/xla_extension/include/llvm/AsmParser/LLLexer.h +131 -0
- deps/exla/cache/xla_extension/include/llvm/AsmParser/LLParser.h +682 -0
- deps/exla/cache/xla_extension/include/llvm/AsmParser/LLToken.h +517 -0
- deps/exla/cache/xla_extension/include/llvm/AsmParser/NumberedValues.h +34 -0
- deps/exla/cache/xla_extension/include/llvm/AsmParser/Parser.h +214 -0
- deps/exla/cache/xla_extension/include/llvm/AsmParser/SlotMapping.h +42 -0
- deps/exla/cache/xla_extension/include/llvm/Debuginfod/BuildIDFetcher.h +36 -0
- deps/exla/cache/xla_extension/include/llvm/Debuginfod/Debuginfod.h +164 -0
- deps/exla/cache/xla_extension/include/llvm/Debuginfod/HTTPClient.h +88 -0
- deps/exla/cache/xla_extension/include/llvm/Debuginfod/HTTPServer.h +133 -0
- deps/exla/cache/xla_extension/include/llvm/Demangle/Demangle.h +143 -0
- deps/exla/cache/xla_extension/include/llvm/Demangle/DemangleConfig.h +97 -0
- deps/exla/cache/xla_extension/include/llvm/Demangle/ItaniumDemangle.h +0 -0
- deps/exla/cache/xla_extension/include/llvm/Demangle/ItaniumNodes.def +104 -0
- deps/exla/cache/xla_extension/include/llvm/Demangle/MicrosoftDemangle.h +301 -0
- deps/exla/cache/xla_extension/include/llvm/Demangle/MicrosoftDemangleNodes.h +651 -0
- deps/exla/cache/xla_extension/include/llvm/Demangle/StringViewExtras.h +38 -0
- deps/exla/cache/xla_extension/include/llvm/Demangle/Utility.h +229 -0
- deps/exla/cache/xla_extension/include/llvm/InitializePasses.h +332 -0
- deps/exla/cache/xla_extension/include/llvm/LinkAllIR.h +54 -0
- deps/exla/cache/xla_extension/include/llvm/LinkAllPasses.h +162 -0
- deps/exla/cache/xla_extension/include/llvm/Pass.h +356 -0
- deps/exla/cache/xla_extension/include/llvm/PassAnalysisSupport.h +293 -0
- deps/exla/cache/xla_extension/include/llvm/PassInfo.h +94 -0
- deps/exla/cache/xla_extension/include/llvm/PassRegistry.h +86 -0
- deps/exla/cache/xla_extension/include/llvm/PassSupport.h +124 -0
- deps/exla/cache/xla_extension/include/llvm/Passes/CodeGenPassBuilder.h +1266 -0
- deps/exla/cache/xla_extension/include/llvm/Passes/MachinePassRegistry.def +331 -0
- deps/exla/cache/xla_extension/include/llvm/Passes/OptimizationLevel.h +127 -0
- deps/exla/cache/xla_extension/include/llvm/Passes/PassBuilder.h +985 -0
- deps/exla/cache/xla_extension/include/llvm/Passes/PassPlugin.h +113 -0
- deps/exla/cache/xla_extension/include/llvm/Passes/StandardInstrumentations.h +641 -0
- deps/exla/cache/xla_extension/include/llvm/Passes/TargetPassRegistry.inc +198 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/CtxInstrContextNode.h +157 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/DataAccessProf.h +220 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/FunctionId.h +213 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/GCOV.h +323 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/HashKeyMap.h +129 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/IndexedMemProfData.h +96 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/InstrProf.h +1350 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/InstrProfCorrelator.h +254 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/InstrProfData.inc +1001 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/InstrProfReader.h +906 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/InstrProfWriter.h +260 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/ItaniumManglingCanonicalizer.h +93 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/MIBEntryDef.inc +55 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/MemProf.h +859 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/MemProfCommon.h +35 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/MemProfData.inc +235 -0
- deps/exla/cache/xla_extension/include/llvm/ProfileData/MemProfRadixTree.h +358 -0
deps/exla/cache/xla_extension/include/llvm/AsmParser/LLLexer.h
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- LLLexer.h - Lexer for LLVM Assembly Files ----------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This class represents the Lexer for .ll files.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_ASMPARSER_LLLEXER_H
|
| 14 |
+
#define LLVM_ASMPARSER_LLLEXER_H
|
| 15 |
+
|
| 16 |
+
#include "LLToken.h"
|
| 17 |
+
#include "llvm/ADT/APFloat.h"
|
| 18 |
+
#include "llvm/ADT/APSInt.h"
|
| 19 |
+
#include "llvm/Support/SMLoc.h"
|
| 20 |
+
#include <string>
|
| 21 |
+
|
| 22 |
+
namespace llvm {
|
| 23 |
+
class Type;
|
| 24 |
+
class SMDiagnostic;
|
| 25 |
+
class SourceMgr;
|
| 26 |
+
class LLVMContext;
|
| 27 |
+
|
| 28 |
+
class LLLexer {
|
| 29 |
+
const char *CurPtr;
|
| 30 |
+
StringRef CurBuf;
|
| 31 |
+
|
| 32 |
+
enum class ErrorPriority {
|
| 33 |
+
None, // No error message present.
|
| 34 |
+
Parser, // Errors issued by parser.
|
| 35 |
+
Lexer, // Errors issued by lexer.
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
struct ErrorInfo {
|
| 39 |
+
ErrorPriority Priority = ErrorPriority::None;
|
| 40 |
+
SMDiagnostic &Error;
|
| 41 |
+
|
| 42 |
+
explicit ErrorInfo(SMDiagnostic &Error) : Error(Error) {}
|
| 43 |
+
} ErrorInfo;
|
| 44 |
+
|
| 45 |
+
SourceMgr &SM;
|
| 46 |
+
LLVMContext &Context;
|
| 47 |
+
|
| 48 |
+
// Information about the current token.
|
| 49 |
+
const char *TokStart;
|
| 50 |
+
lltok::Kind CurKind;
|
| 51 |
+
std::string StrVal;
|
| 52 |
+
unsigned UIntVal = 0;
|
| 53 |
+
Type *TyVal = nullptr;
|
| 54 |
+
APFloat APFloatVal{0.0};
|
| 55 |
+
APSInt APSIntVal{0};
|
| 56 |
+
|
| 57 |
+
// When false (default), an identifier ending in ':' is a label token.
|
| 58 |
+
// When true, the ':' is treated as a separate token.
|
| 59 |
+
bool IgnoreColonInIdentifiers = false;
|
| 60 |
+
|
| 61 |
+
public:
|
| 62 |
+
explicit LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &,
|
| 63 |
+
LLVMContext &C);
|
| 64 |
+
|
| 65 |
+
lltok::Kind Lex() {
|
| 66 |
+
return CurKind = LexToken();
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
typedef SMLoc LocTy;
|
| 70 |
+
LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
|
| 71 |
+
lltok::Kind getKind() const { return CurKind; }
|
| 72 |
+
const std::string &getStrVal() const { return StrVal; }
|
| 73 |
+
Type *getTyVal() const { return TyVal; }
|
| 74 |
+
unsigned getUIntVal() const { return UIntVal; }
|
| 75 |
+
const APSInt &getAPSIntVal() const { return APSIntVal; }
|
| 76 |
+
const APFloat &getAPFloatVal() const { return APFloatVal; }
|
| 77 |
+
|
| 78 |
+
void setIgnoreColonInIdentifiers(bool val) {
|
| 79 |
+
IgnoreColonInIdentifiers = val;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
// This returns true as a convenience for the parser functions that return
|
| 83 |
+
// true on error.
|
| 84 |
+
bool ParseError(LocTy ErrorLoc, const Twine &Msg) {
|
| 85 |
+
Error(ErrorLoc, Msg, ErrorPriority::Parser);
|
| 86 |
+
return true;
|
| 87 |
+
}
|
| 88 |
+
bool ParseError(const Twine &Msg) { return ParseError(getLoc(), Msg); }
|
| 89 |
+
|
| 90 |
+
void Warning(LocTy WarningLoc, const Twine &Msg) const;
|
| 91 |
+
void Warning(const Twine &Msg) const { return Warning(getLoc(), Msg); }
|
| 92 |
+
|
| 93 |
+
private:
|
| 94 |
+
lltok::Kind LexToken();
|
| 95 |
+
|
| 96 |
+
int getNextChar();
|
| 97 |
+
void SkipLineComment();
|
| 98 |
+
bool SkipCComment();
|
| 99 |
+
lltok::Kind ReadString(lltok::Kind kind);
|
| 100 |
+
bool ReadVarName();
|
| 101 |
+
|
| 102 |
+
lltok::Kind LexIdentifier();
|
| 103 |
+
lltok::Kind LexDigitOrNegative();
|
| 104 |
+
lltok::Kind LexPositive();
|
| 105 |
+
lltok::Kind LexAt();
|
| 106 |
+
lltok::Kind LexDollar();
|
| 107 |
+
lltok::Kind LexExclaim();
|
| 108 |
+
lltok::Kind LexPercent();
|
| 109 |
+
lltok::Kind LexUIntID(lltok::Kind Token);
|
| 110 |
+
lltok::Kind LexVar(lltok::Kind Var, lltok::Kind VarID);
|
| 111 |
+
lltok::Kind LexQuote();
|
| 112 |
+
lltok::Kind Lex0x();
|
| 113 |
+
lltok::Kind LexHash();
|
| 114 |
+
lltok::Kind LexCaret();
|
| 115 |
+
|
| 116 |
+
uint64_t atoull(const char *Buffer, const char *End);
|
| 117 |
+
uint64_t HexIntToVal(const char *Buffer, const char *End);
|
| 118 |
+
void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
|
| 119 |
+
void FP80HexToIntPair(const char *Buffer, const char *End,
|
| 120 |
+
uint64_t Pair[2]);
|
| 121 |
+
|
| 122 |
+
void Error(LocTy ErrorLoc, const Twine &Msg, ErrorPriority Origin);
|
| 123 |
+
|
| 124 |
+
void LexError(LocTy ErrorLoc, const Twine &Msg) {
|
| 125 |
+
Error(ErrorLoc, Msg, ErrorPriority::Lexer);
|
| 126 |
+
}
|
| 127 |
+
void LexError(const Twine &Msg) { LexError(getLoc(), Msg); }
|
| 128 |
+
};
|
| 129 |
+
} // end namespace llvm
|
| 130 |
+
|
| 131 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/AsmParser/LLParser.h
ADDED
|
@@ -0,0 +1,682 @@
|
|
|
|
|
|
|
|
|
|
|
|
|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ser Class -------------------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines the parser class for .ll files.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_ASMPARSER_LLPARSER_H
|
| 14 |
+
#define LLVM_ASMPARSER_LLPARSER_H
|
| 15 |
+
|
| 16 |
+
#include "LLLexer.h"
|
| 17 |
+
#include "llvm/ADT/StringMap.h"
|
| 18 |
+
#include "llvm/AsmParser/NumberedValues.h"
|
| 19 |
+
#include "llvm/AsmParser/Parser.h"
|
| 20 |
+
#include "llvm/IR/Attributes.h"
|
| 21 |
+
#include "llvm/IR/FMF.h"
|
| 22 |
+
#include "llvm/IR/Instructions.h"
|
| 23 |
+
#include "llvm/IR/ModuleSummaryIndex.h"
|
| 24 |
+
#include "llvm/Support/ModRef.h"
|
| 25 |
+
#include <map>
|
| 26 |
+
#include <optional>
|
| 27 |
+
|
| 28 |
+
namespace llvm {
|
| 29 |
+
class Module;
|
| 30 |
+
class ConstantRange;
|
| 31 |
+
class FunctionType;
|
| 32 |
+
class GlobalObject;
|
| 33 |
+
class SMDiagnostic;
|
| 34 |
+
class SMLoc;
|
| 35 |
+
class SourceMgr;
|
| 36 |
+
class Type;
|
| 37 |
+
struct MaybeAlign;
|
| 38 |
+
class Function;
|
| 39 |
+
class Value;
|
| 40 |
+
class BasicBlock;
|
| 41 |
+
class Instruction;
|
| 42 |
+
class Constant;
|
| 43 |
+
class GlobalValue;
|
| 44 |
+
class Comdat;
|
| 45 |
+
class MDString;
|
| 46 |
+
class MDNode;
|
| 47 |
+
struct SlotMapping;
|
| 48 |
+
|
| 49 |
+
/// ValID - Represents a reference of a definition of some sort with no type.
|
| 50 |
+
/// There are several cases where we have to parse the value but where the
|
| 51 |
+
/// type can depend on later context. This may either be a numeric reference
|
| 52 |
+
/// or a symbolic (%var) reference. This is just a discriminated union.
|
| 53 |
+
struct ValID {
|
| 54 |
+
enum {
|
| 55 |
+
t_LocalID, // ID in UIntVal.
|
| 56 |
+
t_GlobalID, // ID in UIntVal.
|
| 57 |
+
t_LocalName, // Name in StrVal.
|
| 58 |
+
t_GlobalName, // Name in StrVal.
|
| 59 |
+
t_APSInt, // Value in APSIntVal.
|
| 60 |
+
t_APFloat, // Value in APFloatVal.
|
| 61 |
+
t_Null, // No value.
|
| 62 |
+
t_Undef, // No value.
|
| 63 |
+
t_Zero, // No value.
|
| 64 |
+
t_None, // No value.
|
| 65 |
+
t_Poison, // No value.
|
| 66 |
+
t_EmptyArray, // No value: []
|
| 67 |
+
t_Constant, // Value in ConstantVal.
|
| 68 |
+
t_ConstantSplat, // Value in ConstantVal.
|
| 69 |
+
t_InlineAsm, // Value in FTy/StrVal/StrVal2/UIntVal.
|
| 70 |
+
t_ConstantStruct, // Value in ConstantStructElts.
|
| 71 |
+
t_PackedConstantStruct // Value in ConstantStructElts.
|
| 72 |
+
} Kind = t_LocalID;
|
| 73 |
+
|
| 74 |
+
LLLexer::LocTy Loc;
|
| 75 |
+
unsigned UIntVal;
|
| 76 |
+
FunctionType *FTy = nullptr;
|
| 77 |
+
std::string StrVal, StrVal2;
|
| 78 |
+
APSInt APSIntVal;
|
| 79 |
+
APFloat APFloatVal{0.0};
|
| 80 |
+
Constant *ConstantVal;
|
| 81 |
+
std::unique_ptr<Constant *[]> ConstantStructElts;
|
| 82 |
+
bool NoCFI = false;
|
| 83 |
+
|
| 84 |
+
ValID() = default;
|
| 85 |
+
ValID(const ValID &RHS)
|
| 86 |
+
: Kind(RHS.Kind), Loc(RHS.Loc), UIntVal(RHS.UIntVal), FTy(RHS.FTy),
|
| 87 |
+
StrVal(RHS.StrVal), StrVal2(RHS.StrVal2), APSIntVal(RHS.APSIntVal),
|
| 88 |
+
APFloatVal(RHS.APFloatVal), ConstantVal(RHS.ConstantVal),
|
| 89 |
+
NoCFI(RHS.NoCFI) {
|
| 90 |
+
assert(!RHS.ConstantStructElts);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
bool operator<(const ValID &RHS) const {
|
| 94 |
+
assert((((Kind == t_LocalID || Kind == t_LocalName) &&
|
| 95 |
+
(RHS.Kind == t_LocalID || RHS.Kind == t_LocalName)) ||
|
| 96 |
+
((Kind == t_GlobalID || Kind == t_GlobalName) &&
|
| 97 |
+
(RHS.Kind == t_GlobalID || RHS.Kind == t_GlobalName))) &&
|
| 98 |
+
"Comparing ValIDs of different kinds");
|
| 99 |
+
if (Kind != RHS.Kind)
|
| 100 |
+
return Kind < RHS.Kind;
|
| 101 |
+
if (Kind == t_LocalID || Kind == t_GlobalID)
|
| 102 |
+
return UIntVal < RHS.UIntVal;
|
| 103 |
+
return StrVal < RHS.StrVal;
|
| 104 |
+
}
|
| 105 |
+
};
|
| 106 |
+
|
| 107 |
+
class LLParser {
|
| 108 |
+
public:
|
| 109 |
+
typedef LLLexer::LocTy LocTy;
|
| 110 |
+
private:
|
| 111 |
+
LLVMContext &Context;
|
| 112 |
+
// Lexer to determine whether to use opaque pointers or not.
|
| 113 |
+
LLLexer OPLex;
|
| 114 |
+
LLLexer Lex;
|
| 115 |
+
// Module being parsed, null if we are only parsing summary index.
|
| 116 |
+
Module *M;
|
| 117 |
+
// Summary index being parsed, null if we are only parsing Module.
|
| 118 |
+
ModuleSummaryIndex *Index;
|
| 119 |
+
SlotMapping *Slots;
|
| 120 |
+
|
| 121 |
+
SmallVector<Instruction*, 64> InstsWithTBAATag;
|
| 122 |
+
|
| 123 |
+
/// DIAssignID metadata does not support temporary RAUW so we cannot use
|
| 124 |
+
/// the normal metadata forward reference resolution method. Instead,
|
| 125 |
+
/// non-temporary DIAssignID are attached to instructions (recorded here)
|
| 126 |
+
/// then replaced later.
|
| 127 |
+
DenseMap<MDNode *, SmallVector<Instruction *, 2>> TempDIAssignIDAttachments;
|
| 128 |
+
|
| 129 |
+
// Type resolution handling data structures. The location is set when we
|
| 130 |
+
// have processed a use of the type but not a definition yet.
|
| 131 |
+
StringMap<std::pair<Type*, LocTy> > NamedTypes;
|
| 132 |
+
std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes;
|
| 133 |
+
|
| 134 |
+
std::map<unsigned, TrackingMDNodeRef> NumberedMetadata;
|
| 135 |
+
std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes;
|
| 136 |
+
|
| 137 |
+
// Global Value reference information.
|
| 138 |
+
std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
|
| 139 |
+
std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
|
| 140 |
+
NumberedValues<GlobalValue *> NumberedVals;
|
| 141 |
+
|
| 142 |
+
// Comdat forward reference information.
|
| 143 |
+
std::map<std::string, LocTy> ForwardRefComdats;
|
| 144 |
+
|
| 145 |
+
// References to blockaddress. The key is the function ValID, the value is
|
| 146 |
+
// a list of references to blocks in that function.
|
| 147 |
+
std::map<ValID, std::map<ValID, GlobalValue *>> ForwardRefBlockAddresses;
|
| 148 |
+
class PerFunctionState;
|
| 149 |
+
/// Reference to per-function state to allow basic blocks to be
|
| 150 |
+
/// forward-referenced by blockaddress instructions within the same
|
| 151 |
+
/// function.
|
| 152 |
+
PerFunctionState *BlockAddressPFS;
|
| 153 |
+
|
| 154 |
+
// References to dso_local_equivalent. The key is the global's ValID, the
|
| 155 |
+
// value is a placeholder value that will be replaced. Note there are two
|
| 156 |
+
// maps for tracking ValIDs that are GlobalNames and ValIDs that are
|
| 157 |
+
// GlobalIDs. These are needed because "operator<" doesn't discriminate
|
| 158 |
+
// between the two.
|
| 159 |
+
std::map<ValID, GlobalValue *> ForwardRefDSOLocalEquivalentNames;
|
| 160 |
+
std::map<ValID, GlobalValue *> ForwardRefDSOLocalEquivalentIDs;
|
| 161 |
+
|
| 162 |
+
// Attribute builder reference information.
|
| 163 |
+
std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
|
| 164 |
+
std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
|
| 165 |
+
|
| 166 |
+
// Summary global value reference information.
|
| 167 |
+
std::map<unsigned, std::vector<std::pair<ValueInfo *, LocTy>>>
|
| 168 |
+
ForwardRefValueInfos;
|
| 169 |
+
std::map<unsigned, std::vector<std::pair<AliasSummary *, LocTy>>>
|
| 170 |
+
ForwardRefAliasees;
|
| 171 |
+
std::vector<ValueInfo> NumberedValueInfos;
|
| 172 |
+
|
| 173 |
+
// Summary type id reference information.
|
| 174 |
+
std::map<unsigned, std::vector<std::pair<GlobalValue::GUID *, LocTy>>>
|
| 175 |
+
ForwardRefTypeIds;
|
| 176 |
+
|
| 177 |
+
// Map of module ID to path.
|
| 178 |
+
std::map<unsigned, StringRef> ModuleIdMap;
|
| 179 |
+
|
| 180 |
+
/// Only the llvm-as tool may set this to false to bypass
|
| 181 |
+
/// UpgradeDebuginfo so it can generate broken bitcode.
|
| 182 |
+
bool UpgradeDebugInfo;
|
| 183 |
+
|
| 184 |
+
bool SeenNewDbgInfoFormat = false;
|
| 185 |
+
bool SeenOldDbgInfoFormat = false;
|
| 186 |
+
|
| 187 |
+
std::string SourceFileName;
|
| 188 |
+
|
| 189 |
+
public:
|
| 190 |
+
LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M,
|
| 191 |
+
ModuleSummaryIndex *Index, LLVMContext &Context,
|
| 192 |
+
SlotMapping *Slots = nullptr)
|
| 193 |
+
: Context(Context), OPLex(F, SM, Err, Context),
|
| 194 |
+
Lex(F, SM, Err, Context), M(M), Index(Index), Slots(Slots),
|
| 195 |
+
BlockAddressPFS(nullptr) {}
|
| 196 |
+
bool Run(
|
| 197 |
+
bool UpgradeDebugInfo,
|
| 198 |
+
DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) {
|
| 199 |
+
return std::nullopt;
|
| 200 |
+
});
|
| 201 |
+
|
| 202 |
+
bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots);
|
| 203 |
+
|
| 204 |
+
bool parseTypeAtBeginning(Type *&Ty, unsigned &Read,
|
| 205 |
+
const SlotMapping *Slots);
|
| 206 |
+
|
| 207 |
+
bool parseDIExpressionBodyAtBeginning(MDNode *&Result, unsigned &Read,
|
| 208 |
+
const SlotMapping *Slots);
|
| 209 |
+
|
| 210 |
+
LLVMContext &getContext() { return Context; }
|
| 211 |
+
|
| 212 |
+
private:
|
| 213 |
+
bool error(LocTy L, const Twine &Msg) { return Lex.ParseError(L, Msg); }
|
| 214 |
+
bool tokError(const Twine &Msg) { return error(Lex.getLoc(), Msg); }
|
| 215 |
+
|
| 216 |
+
bool checkValueID(LocTy L, StringRef Kind, StringRef Prefix,
|
| 217 |
+
unsigned NextID, unsigned ID);
|
| 218 |
+
|
| 219 |
+
/// Restore the internal name and slot mappings using the mappings that
|
| 220 |
+
/// were created at an earlier parsing stage.
|
| 221 |
+
void restoreParsingState(const SlotMapping *Slots);
|
| 222 |
+
|
| 223 |
+
/// getGlobalVal - Get a value with the specified name or ID, creating a
|
| 224 |
+
/// forward reference record if needed. This can return null if the value
|
| 225 |
+
/// exists but does not have the right type.
|
| 226 |
+
GlobalValue *getGlobalVal(const std::string &N, Type *Ty, LocTy Loc);
|
| 227 |
+
GlobalValue *getGlobalVal(unsigned ID, Type *Ty, LocTy Loc);
|
| 228 |
+
|
| 229 |
+
/// Get a Comdat with the specified name, creating a forward reference
|
| 230 |
+
/// record if needed.
|
| 231 |
+
Comdat *getComdat(const std::string &Name, LocTy Loc);
|
| 232 |
+
|
| 233 |
+
// Helper Routines.
|
| 234 |
+
bool parseToken(lltok::Kind T, const char *ErrMsg);
|
| 235 |
+
bool EatIfPresent(lltok::Kind T) {
|
| 236 |
+
if (Lex.getKind() != T) return false;
|
| 237 |
+
Lex.Lex();
|
| 238 |
+
return true;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
FastMathFlags EatFastMathFlagsIfPresent() {
|
| 242 |
+
FastMathFlags FMF;
|
| 243 |
+
while (true)
|
| 244 |
+
switch (Lex.getKind()) {
|
| 245 |
+
case lltok::kw_fast: FMF.setFast(); Lex.Lex(); continue;
|
| 246 |
+
case lltok::kw_nnan: FMF.setNoNaNs(); Lex.Lex(); continue;
|
| 247 |
+
case lltok::kw_ninf: FMF.setNoInfs(); Lex.Lex(); continue;
|
| 248 |
+
case lltok::kw_nsz: FMF.setNoSignedZeros(); Lex.Lex(); continue;
|
| 249 |
+
case lltok::kw_arcp: FMF.setAllowReciprocal(); Lex.Lex(); continue;
|
| 250 |
+
case lltok::kw_contract:
|
| 251 |
+
FMF.setAllowContract(true);
|
| 252 |
+
Lex.Lex();
|
| 253 |
+
continue;
|
| 254 |
+
case lltok::kw_reassoc: FMF.setAllowReassoc(); Lex.Lex(); continue;
|
| 255 |
+
case lltok::kw_afn: FMF.setApproxFunc(); Lex.Lex(); continue;
|
| 256 |
+
default: return FMF;
|
| 257 |
+
}
|
| 258 |
+
return FMF;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
bool parseOptionalToken(lltok::Kind T, bool &Present,
|
| 262 |
+
LocTy *Loc = nullptr) {
|
| 263 |
+
if (Lex.getKind() != T) {
|
| 264 |
+
Present = false;
|
| 265 |
+
} else {
|
| 266 |
+
if (Loc)
|
| 267 |
+
*Loc = Lex.getLoc();
|
| 268 |
+
Lex.Lex();
|
| 269 |
+
Present = true;
|
| 270 |
+
}
|
| 271 |
+
return false;
|
| 272 |
+
}
|
| 273 |
+
bool parseStringConstant(std::string &Result);
|
| 274 |
+
bool parseUInt32(unsigned &Val);
|
| 275 |
+
bool parseUInt32(unsigned &Val, LocTy &Loc) {
|
| 276 |
+
Loc = Lex.getLoc();
|
| 277 |
+
return parseUInt32(Val);
|
| 278 |
+
}
|
| 279 |
+
bool parseUInt64(uint64_t &Val);
|
| 280 |
+
bool parseUInt64(uint64_t &Val, LocTy &Loc) {
|
| 281 |
+
Loc = Lex.getLoc();
|
| 282 |
+
return parseUInt64(Val);
|
| 283 |
+
}
|
| 284 |
+
bool parseFlag(unsigned &Val);
|
| 285 |
+
|
| 286 |
+
bool parseStringAttribute(AttrBuilder &B);
|
| 287 |
+
|
| 288 |
+
bool parseTLSModel(GlobalVariable::ThreadLocalMode &TLM);
|
| 289 |
+
bool parseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM);
|
| 290 |
+
bool parseOptionalUnnamedAddr(GlobalVariable::UnnamedAddr &UnnamedAddr);
|
| 291 |
+
bool parseOptionalAddrSpace(unsigned &AddrSpace, unsigned DefaultAS = 0);
|
| 292 |
+
bool parseOptionalProgramAddrSpace(unsigned &AddrSpace) {
|
| 293 |
+
return parseOptionalAddrSpace(
|
| 294 |
+
AddrSpace, M->getDataLayout().getProgramAddressSpace());
|
| 295 |
+
};
|
| 296 |
+
bool parseEnumAttribute(Attribute::AttrKind Attr, AttrBuilder &B,
|
| 297 |
+
bool InAttrGroup);
|
| 298 |
+
bool parseOptionalParamOrReturnAttrs(AttrBuilder &B, bool IsParam);
|
| 299 |
+
bool parseOptionalParamAttrs(AttrBuilder &B) {
|
| 300 |
+
return parseOptionalParamOrReturnAttrs(B, true);
|
| 301 |
+
}
|
| 302 |
+
bool parseOptionalReturnAttrs(AttrBuilder &B) {
|
| 303 |
+
return parseOptionalParamOrReturnAttrs(B, false);
|
| 304 |
+
}
|
| 305 |
+
bool parseOptionalLinkage(unsigned &Res, bool &HasLinkage,
|
| 306 |
+
unsigned &Visibility, unsigned &DLLStorageClass,
|
| 307 |
+
bool &DSOLocal);
|
| 308 |
+
void parseOptionalDSOLocal(bool &DSOLocal);
|
| 309 |
+
void parseOptionalVisibility(unsigned &Res);
|
| 310 |
+
bool parseOptionalImportType(lltok::Kind Kind,
|
| 311 |
+
GlobalValueSummary::ImportKind &Res);
|
| 312 |
+
void parseOptionalDLLStorageClass(unsigned &Res);
|
| 313 |
+
bool parseOptionalCallingConv(unsigned &CC);
|
| 314 |
+
bool parseOptionalAlignment(MaybeAlign &Alignment,
|
| 315 |
+
bool AllowParens = false);
|
| 316 |
+
bool parseOptionalCodeModel(CodeModel::Model &model);
|
| 317 |
+
bool parseOptionalDerefAttrBytes(lltok::Kind AttrKind, uint64_t &Bytes);
|
| 318 |
+
bool parseOptionalUWTableKind(UWTableKind &Kind);
|
| 319 |
+
bool parseAllocKind(AllocFnKind &Kind);
|
| 320 |
+
std::optional<MemoryEffects> parseMemoryAttr();
|
| 321 |
+
unsigned parseNoFPClassAttr();
|
| 322 |
+
bool parseScopeAndOrdering(bool IsAtomic, SyncScope::ID &SSID,
|
| 323 |
+
AtomicOrdering &Ordering);
|
| 324 |
+
bool parseScope(SyncScope::ID &SSID);
|
| 325 |
+
bool parseOrdering(AtomicOrdering &Ordering);
|
| 326 |
+
bool parseOptionalStackAlignment(unsigned &Alignment);
|
| 327 |
+
bool parseOptionalCommaAlign(MaybeAlign &Alignment, bool &AteExtraComma);
|
| 328 |
+
bool parseOptionalCommaAddrSpace(unsigned &AddrSpace, LocTy &Loc,
|
| 329 |
+
bool &AteExtraComma);
|
| 330 |
+
bool parseAllocSizeArguments(unsigned &BaseSizeArg,
|
| 331 |
+
std::optional<unsigned> &HowManyArg);
|
| 332 |
+
bool parseVScaleRangeArguments(unsigned &MinValue, unsigned &MaxValue);
|
| 333 |
+
bool parseIndexList(SmallVectorImpl<unsigned> &Indices,
|
| 334 |
+
bool &AteExtraComma);
|
| 335 |
+
bool parseIndexList(SmallVectorImpl<unsigned> &Indices) {
|
| 336 |
+
bool AteExtraComma;
|
| 337 |
+
if (parseIndexList(Indices, AteExtraComma))
|
| 338 |
+
return true;
|
| 339 |
+
if (AteExtraComma)
|
| 340 |
+
return tokError("expected index");
|
| 341 |
+
return false;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
// Top-Level Entities
|
| 345 |
+
bool parseTopLevelEntities();
|
| 346 |
+
void dropUnknownMetadataReferences();
|
| 347 |
+
bool validateEndOfModule(bool UpgradeDebugInfo);
|
| 348 |
+
bool validateEndOfIndex();
|
| 349 |
+
bool parseTargetDefinitions(DataLayoutCallbackTy DataLayoutCallback);
|
| 350 |
+
bool parseTargetDefinition(std::string &TentativeDLStr, LocTy &DLStrLoc);
|
| 351 |
+
bool parseModuleAsm();
|
| 352 |
+
bool parseSourceFileName();
|
| 353 |
+
bool parseUnnamedType();
|
| 354 |
+
bool parseNamedType();
|
| 355 |
+
bool parseDeclare();
|
| 356 |
+
bool parseDefine();
|
| 357 |
+
|
| 358 |
+
bool parseGlobalType(bool &IsConstant);
|
| 359 |
+
bool parseUnnamedGlobal();
|
| 360 |
+
bool parseNamedGlobal();
|
| 361 |
+
bool parseGlobal(const std::string &Name, unsigned NameID, LocTy NameLoc,
|
| 362 |
+
unsigned Linkage, bool HasLinkage, unsigned Visibility,
|
| 363 |
+
unsigned DLLStorageClass, bool DSOLocal,
|
| 364 |
+
GlobalVariable::ThreadLocalMode TLM,
|
| 365 |
+
GlobalVariable::UnnamedAddr UnnamedAddr);
|
| 366 |
+
bool parseAliasOrIFunc(const std::string &Name, unsigned NameID,
|
| 367 |
+
LocTy NameLoc, unsigned L, unsigned Visibility,
|
| 368 |
+
unsigned DLLStorageClass, bool DSOLocal,
|
| 369 |
+
GlobalVariable::ThreadLocalMode TLM,
|
| 370 |
+
GlobalVariable::UnnamedAddr UnnamedAddr);
|
| 371 |
+
bool parseComdat();
|
| 372 |
+
bool parseStandaloneMetadata();
|
| 373 |
+
bool parseNamedMetadata();
|
| 374 |
+
bool parseMDString(MDString *&Result);
|
| 375 |
+
bool parseMDNodeID(MDNode *&Result);
|
| 376 |
+
bool parseUnnamedAttrGrp();
|
| 377 |
+
bool parseFnAttributeValuePairs(AttrBuilder &B,
|
| 378 |
+
std::vector<unsigned> &FwdRefAttrGrps,
|
| 379 |
+
bool inAttrGrp, LocTy &BuiltinLoc);
|
| 380 |
+
bool parseRangeAttr(AttrBuilder &B);
|
| 381 |
+
bool parseInitializesAttr(AttrBuilder &B);
|
| 382 |
+
bool parseCapturesAttr(AttrBuilder &B);
|
| 383 |
+
bool parseRequiredTypeAttr(AttrBuilder &B, lltok::Kind AttrToken,
|
| 384 |
+
Attribute::AttrKind AttrKind);
|
| 385 |
+
|
| 386 |
+
// Module Summary Index Parsing.
|
| 387 |
+
bool skipModuleSummaryEntry();
|
| 388 |
+
bool parseSummaryEntry();
|
| 389 |
+
bool parseModuleEntry(unsigned ID);
|
| 390 |
+
bool parseModuleReference(StringRef &ModulePath);
|
| 391 |
+
bool parseGVReference(ValueInfo &VI, unsigned &GVId);
|
| 392 |
+
bool parseSummaryIndexFlags();
|
| 393 |
+
bool parseBlockCount();
|
| 394 |
+
bool parseGVEntry(unsigned ID);
|
| 395 |
+
bool parseFunctionSummary(std::string Name, GlobalValue::GUID, unsigned ID);
|
| 396 |
+
bool parseVariableSummary(std::string Name, GlobalValue::GUID, unsigned ID);
|
| 397 |
+
bool parseAliasSummary(std::string Name, GlobalValue::GUID, unsigned ID);
|
| 398 |
+
bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
|
| 399 |
+
bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
|
| 400 |
+
bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
|
| 401 |
+
bool parseOptionalCalls(SmallVectorImpl<FunctionSummary::EdgeTy> &Calls);
|
| 402 |
+
bool parseHotness(CalleeInfo::HotnessType &Hotness);
|
| 403 |
+
bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
|
| 404 |
+
bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
|
| 405 |
+
bool parseVFuncIdList(lltok::Kind Kind,
|
| 406 |
+
std::vector<FunctionSummary::VFuncId> &VFuncIdList);
|
| 407 |
+
bool parseConstVCallList(
|
| 408 |
+
lltok::Kind Kind,
|
| 409 |
+
std::vector<FunctionSummary::ConstVCall> &ConstVCallList);
|
| 410 |
+
using IdToIndexMapType =
|
| 411 |
+
std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>;
|
| 412 |
+
bool parseConstVCall(FunctionSummary::ConstVCall &ConstVCall,
|
| 413 |
+
IdToIndexMapType &IdToIndexMap, unsigned Index);
|
| 414 |
+
bool parseVFuncId(FunctionSummary::VFuncId &VFuncId,
|
| 415 |
+
IdToIndexMapType &IdToIndexMap, unsigned Index);
|
| 416 |
+
bool parseOptionalVTableFuncs(VTableFuncList &VTableFuncs);
|
| 417 |
+
bool parseOptionalParamAccesses(
|
| 418 |
+
std::vector<FunctionSummary::ParamAccess> &Params);
|
| 419 |
+
bool parseParamNo(uint64_t &ParamNo);
|
| 420 |
+
using IdLocListType = std::vector<std::pair<unsigned, LocTy>>;
|
| 421 |
+
bool parseParamAccess(FunctionSummary::ParamAccess &Param,
|
| 422 |
+
IdLocListType &IdLocList);
|
| 423 |
+
bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &Call,
|
| 424 |
+
IdLocListType &IdLocList);
|
| 425 |
+
bool parseParamAccessOffset(ConstantRange &Range);
|
| 426 |
+
bool parseOptionalRefs(SmallVectorImpl<ValueInfo> &Refs);
|
| 427 |
+
bool parseTypeIdEntry(unsigned ID);
|
| 428 |
+
bool parseTypeIdSummary(TypeIdSummary &TIS);
|
| 429 |
+
bool parseTypeIdCompatibleVtableEntry(unsigned ID);
|
| 430 |
+
bool parseTypeTestResolution(TypeTestResolution &TTRes);
|
| 431 |
+
bool parseOptionalWpdResolutions(
|
| 432 |
+
std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap);
|
| 433 |
+
bool parseWpdRes(WholeProgramDevirtResolution &WPDRes);
|
| 434 |
+
bool parseOptionalResByArg(
|
| 435 |
+
std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
|
| 436 |
+
&ResByArg);
|
| 437 |
+
bool parseArgs(std::vector<uint64_t> &Args);
|
| 438 |
+
bool addGlobalValueToIndex(std::string Name, GlobalValue::GUID,
|
| 439 |
+
GlobalValue::LinkageTypes Linkage, unsigned ID,
|
| 440 |
+
std::unique_ptr<GlobalValueSummary> Summary,
|
| 441 |
+
LocTy Loc);
|
| 442 |
+
bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
|
| 443 |
+
bool parseMemProfs(std::vector<MIBInfo> &MIBs);
|
| 444 |
+
bool parseAllocType(uint8_t &AllocType);
|
| 445 |
+
bool parseOptionalCallsites(std::vector<CallsiteInfo> &Callsites);
|
| 446 |
+
|
| 447 |
+
// Type Parsing.
|
| 448 |
+
bool parseType(Type *&Result, const Twine &Msg, bool AllowVoid = false);
|
| 449 |
+
bool parseType(Type *&Result, bool AllowVoid = false) {
|
| 450 |
+
return parseType(Result, "expected type", AllowVoid);
|
| 451 |
+
}
|
| 452 |
+
bool parseType(Type *&Result, const Twine &Msg, LocTy &Loc,
|
| 453 |
+
bool AllowVoid = false) {
|
| 454 |
+
Loc = Lex.getLoc();
|
| 455 |
+
return parseType(Result, Msg, AllowVoid);
|
| 456 |
+
}
|
| 457 |
+
bool parseType(Type *&Result, LocTy &Loc, bool AllowVoid = false) {
|
| 458 |
+
Loc = Lex.getLoc();
|
| 459 |
+
return parseType(Result, AllowVoid);
|
| 460 |
+
}
|
| 461 |
+
bool parseAnonStructType(Type *&Result, bool Packed);
|
| 462 |
+
bool parseStructBody(SmallVectorImpl<Type *> &Body);
|
| 463 |
+
bool parseStructDefinition(SMLoc TypeLoc, StringRef Name,
|
| 464 |
+
std::pair<Type *, LocTy> &Entry,
|
| 465 |
+
Type *&ResultTy);
|
| 466 |
+
|
| 467 |
+
bool parseArrayVectorType(Type *&Result, bool IsVector);
|
| 468 |
+
bool parseFunctionType(Type *&Result);
|
| 469 |
+
bool parseTargetExtType(Type *&Result);
|
| 470 |
+
|
| 471 |
+
// Function Semantic Analysis.
|
| 472 |
+
class PerFunctionState {
|
| 473 |
+
LLParser &P;
|
| 474 |
+
Function &F;
|
| 475 |
+
std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
|
| 476 |
+
std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
|
| 477 |
+
NumberedValues<Value *> NumberedVals;
|
| 478 |
+
|
| 479 |
+
/// FunctionNumber - If this is an unnamed function, this is the slot
|
| 480 |
+
/// number of it, otherwise it is -1.
|
| 481 |
+
int FunctionNumber;
|
| 482 |
+
|
| 483 |
+
public:
|
| 484 |
+
PerFunctionState(LLParser &p, Function &f, int functionNumber,
|
| 485 |
+
ArrayRef<unsigned> UnnamedArgNums);
|
| 486 |
+
~PerFunctionState();
|
| 487 |
+
|
| 488 |
+
Function &getFunction() const { return F; }
|
| 489 |
+
|
| 490 |
+
bool finishFunction();
|
| 491 |
+
|
| 492 |
+
/// GetVal - Get a value with the specified name or ID, creating a
|
| 493 |
+
/// forward reference record if needed. This can return null if the value
|
| 494 |
+
/// exists but does not have the right type.
|
| 495 |
+
Value *getVal(const std::string &Name, Type *Ty, LocTy Loc);
|
| 496 |
+
Value *getVal(unsigned ID, Type *Ty, LocTy Loc);
|
| 497 |
+
|
| 498 |
+
/// setInstName - After an instruction is parsed and inserted into its
|
| 499 |
+
/// basic block, this installs its name.
|
| 500 |
+
bool setInstName(int NameID, const std::string &NameStr, LocTy NameLoc,
|
| 501 |
+
Instruction *Inst);
|
| 502 |
+
|
| 503 |
+
/// GetBB - Get a basic block with the specified name or ID, creating a
|
| 504 |
+
/// forward reference record if needed. This can return null if the value
|
| 505 |
+
/// is not a BasicBlock.
|
| 506 |
+
BasicBlock *getBB(const std::string &Name, LocTy Loc);
|
| 507 |
+
BasicBlock *getBB(unsigned ID, LocTy Loc);
|
| 508 |
+
|
| 509 |
+
/// DefineBB - Define the specified basic block, which is either named or
|
| 510 |
+
/// unnamed. If there is an error, this returns null otherwise it returns
|
| 511 |
+
/// the block being defined.
|
| 512 |
+
BasicBlock *defineBB(const std::string &Name, int NameID, LocTy Loc);
|
| 513 |
+
|
| 514 |
+
bool resolveForwardRefBlockAddresses();
|
| 515 |
+
};
|
| 516 |
+
|
| 517 |
+
bool convertValIDToValue(Type *Ty, ValID &ID, Value *&V,
|
| 518 |
+
PerFunctionState *PFS);
|
| 519 |
+
|
| 520 |
+
Value *checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty,
|
| 521 |
+
Value *Val);
|
| 522 |
+
|
| 523 |
+
bool parseConstantValue(Type *Ty, Constant *&C);
|
| 524 |
+
bool parseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
|
| 525 |
+
bool parseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
|
| 526 |
+
return parseValue(Ty, V, &PFS);
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
bool parseValue(Type *Ty, Value *&V, LocTy &Loc, PerFunctionState &PFS) {
|
| 530 |
+
Loc = Lex.getLoc();
|
| 531 |
+
return parseValue(Ty, V, &PFS);
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
bool parseTypeAndValue(Value *&V, PerFunctionState *PFS);
|
| 535 |
+
bool parseTypeAndValue(Value *&V, PerFunctionState &PFS) {
|
| 536 |
+
return parseTypeAndValue(V, &PFS);
|
| 537 |
+
}
|
| 538 |
+
bool parseTypeAndValue(Value *&V, LocTy &Loc, PerFunctionState &PFS) {
|
| 539 |
+
Loc = Lex.getLoc();
|
| 540 |
+
return parseTypeAndValue(V, PFS);
|
| 541 |
+
}
|
| 542 |
+
bool parseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc,
|
| 543 |
+
PerFunctionState &PFS);
|
| 544 |
+
bool parseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
|
| 545 |
+
LocTy Loc;
|
| 546 |
+
return parseTypeAndBasicBlock(BB, Loc, PFS);
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
struct ParamInfo {
|
| 550 |
+
LocTy Loc;
|
| 551 |
+
Value *V;
|
| 552 |
+
AttributeSet Attrs;
|
| 553 |
+
ParamInfo(LocTy loc, Value *v, AttributeSet attrs)
|
| 554 |
+
: Loc(loc), V(v), Attrs(attrs) {}
|
| 555 |
+
};
|
| 556 |
+
bool parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
|
| 557 |
+
PerFunctionState &PFS, bool IsMustTailCall = false,
|
| 558 |
+
bool InVarArgsFunc = false);
|
| 559 |
+
|
| 560 |
+
bool
|
| 561 |
+
parseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
|
| 562 |
+
PerFunctionState &PFS);
|
| 563 |
+
|
| 564 |
+
bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
|
| 565 |
+
PerFunctionState &PFS);
|
| 566 |
+
|
| 567 |
+
bool resolveFunctionType(Type *RetType, ArrayRef<ParamInfo> ArgList,
|
| 568 |
+
FunctionType *&FuncTy);
|
| 569 |
+
|
| 570 |
+
// Constant Parsing.
|
| 571 |
+
bool parseValID(ValID &ID, PerFunctionState *PFS,
|
| 572 |
+
Type *ExpectedTy = nullptr);
|
| 573 |
+
bool parseGlobalValue(Type *Ty, Constant *&C);
|
| 574 |
+
bool parseGlobalTypeAndValue(Constant *&V);
|
| 575 |
+
bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts);
|
| 576 |
+
bool parseOptionalComdat(StringRef GlobalName, Comdat *&C);
|
| 577 |
+
bool parseSanitizer(GlobalVariable *GV);
|
| 578 |
+
bool parseMetadataAsValue(Value *&V, PerFunctionState &PFS);
|
| 579 |
+
bool parseValueAsMetadata(Metadata *&MD, const Twine &TypeMsg,
|
| 580 |
+
PerFunctionState *PFS);
|
| 581 |
+
bool parseDIArgList(Metadata *&MD, PerFunctionState *PFS);
|
| 582 |
+
bool parseMetadata(Metadata *&MD, PerFunctionState *PFS);
|
| 583 |
+
bool parseMDTuple(MDNode *&MD, bool IsDistinct = false);
|
| 584 |
+
bool parseMDNode(MDNode *&N);
|
| 585 |
+
bool parseMDNodeTail(MDNode *&N);
|
| 586 |
+
bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
|
| 587 |
+
bool parseMetadataAttachment(unsigned &Kind, MDNode *&MD);
|
| 588 |
+
bool parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS);
|
| 589 |
+
bool parseInstructionMetadata(Instruction &Inst);
|
| 590 |
+
bool parseGlobalObjectMetadataAttachment(GlobalObject &GO);
|
| 591 |
+
bool parseOptionalFunctionMetadata(Function &F);
|
| 592 |
+
|
| 593 |
+
template <class FieldTy>
|
| 594 |
+
bool parseMDField(LocTy Loc, StringRef Name, FieldTy &Result);
|
| 595 |
+
template <class FieldTy> bool parseMDField(StringRef Name, FieldTy &Result);
|
| 596 |
+
template <class ParserTy> bool parseMDFieldsImplBody(ParserTy ParseField);
|
| 597 |
+
template <class ParserTy>
|
| 598 |
+
bool parseMDFieldsImpl(ParserTy ParseField, LocTy &ClosingLoc);
|
| 599 |
+
bool parseSpecializedMDNode(MDNode *&N, bool IsDistinct = false);
|
| 600 |
+
bool parseDIExpressionBody(MDNode *&Result, bool IsDistinct);
|
| 601 |
+
|
| 602 |
+
#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
|
| 603 |
+
bool parse##CLASS(MDNode *&Result, bool IsDistinct);
|
| 604 |
+
#include "llvm/IR/Metadata.def"
|
| 605 |
+
|
| 606 |
+
// Function Parsing.
|
| 607 |
+
struct ArgInfo {
|
| 608 |
+
LocTy Loc;
|
| 609 |
+
Type *Ty;
|
| 610 |
+
AttributeSet Attrs;
|
| 611 |
+
std::string Name;
|
| 612 |
+
ArgInfo(LocTy L, Type *ty, AttributeSet Attr, const std::string &N)
|
| 613 |
+
: Loc(L), Ty(ty), Attrs(Attr), Name(N) {}
|
| 614 |
+
};
|
| 615 |
+
bool parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
|
| 616 |
+
SmallVectorImpl<unsigned> &UnnamedArgNums,
|
| 617 |
+
bool &IsVarArg);
|
| 618 |
+
bool parseFunctionHeader(Function *&Fn, bool IsDefine,
|
| 619 |
+
unsigned &FunctionNumber,
|
| 620 |
+
SmallVectorImpl<unsigned> &UnnamedArgNums);
|
| 621 |
+
bool parseFunctionBody(Function &Fn, unsigned FunctionNumber,
|
| 622 |
+
ArrayRef<unsigned> UnnamedArgNums);
|
| 623 |
+
bool parseBasicBlock(PerFunctionState &PFS);
|
| 624 |
+
|
| 625 |
+
enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };
|
| 626 |
+
|
| 627 |
+
// Instruction Parsing. Each instruction parsing routine can return with a
|
| 628 |
+
// normal result, an error result, or return having eaten an extra comma.
|
| 629 |
+
enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
|
| 630 |
+
int parseInstruction(Instruction *&Inst, BasicBlock *BB,
|
| 631 |
+
PerFunctionState &PFS);
|
| 632 |
+
bool parseCmpPredicate(unsigned &P, unsigned Opc);
|
| 633 |
+
|
| 634 |
+
bool parseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
|
| 635 |
+
bool parseBr(Instruction *&Inst, PerFunctionState &PFS);
|
| 636 |
+
bool parseSwitch(Instruction *&Inst, PerFunctionState &PFS);
|
| 637 |
+
bool parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
|
| 638 |
+
bool parseInvoke(Instruction *&Inst, PerFunctionState &PFS);
|
| 639 |
+
bool parseResume(Instruction *&Inst, PerFunctionState &PFS);
|
| 640 |
+
bool parseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
|
| 641 |
+
bool parseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
|
| 642 |
+
bool parseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
|
| 643 |
+
bool parseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
|
| 644 |
+
bool parseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
|
| 645 |
+
bool parseCallBr(Instruction *&Inst, PerFunctionState &PFS);
|
| 646 |
+
|
| 647 |
+
bool parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc,
|
| 648 |
+
bool IsFP);
|
| 649 |
+
bool parseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
|
| 650 |
+
unsigned Opc, bool IsFP);
|
| 651 |
+
bool parseLogical(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
|
| 652 |
+
bool parseCompare(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
|
| 653 |
+
bool parseCast(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc);
|
| 654 |
+
bool parseSelect(Instruction *&Inst, PerFunctionState &PFS);
|
| 655 |
+
bool parseVAArg(Instruction *&Inst, PerFunctionState &PFS);
|
| 656 |
+
bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
|
| 657 |
+
bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
|
| 658 |
+
bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
|
| 659 |
+
int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
|
| 660 |
+
bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
|
| 661 |
+
bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
|
| 662 |
+
CallInst::TailCallKind TCK);
|
| 663 |
+
int parseAlloc(Instruction *&Inst, PerFunctionState &PFS);
|
| 664 |
+
int parseLoad(Instruction *&Inst, PerFunctionState &PFS);
|
| 665 |
+
int parseStore(Instruction *&Inst, PerFunctionState &PFS);
|
| 666 |
+
int parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS);
|
| 667 |
+
int parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS);
|
| 668 |
+
int parseFence(Instruction *&Inst, PerFunctionState &PFS);
|
| 669 |
+
int parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS);
|
| 670 |
+
int parseExtractValue(Instruction *&Inst, PerFunctionState &PFS);
|
| 671 |
+
int parseInsertValue(Instruction *&Inst, PerFunctionState &PFS);
|
| 672 |
+
bool parseFreeze(Instruction *&I, PerFunctionState &PFS);
|
| 673 |
+
|
| 674 |
+
// Use-list order directives.
|
| 675 |
+
bool parseUseListOrder(PerFunctionState *PFS = nullptr);
|
| 676 |
+
bool parseUseListOrderBB();
|
| 677 |
+
bool parseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes);
|
| 678 |
+
bool sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc);
|
| 679 |
+
};
|
| 680 |
+
} // End llvm namespace
|
| 681 |
+
|
| 682 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/AsmParser/LLToken.h
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- LLToken.h - Token Codes for LLVM Assembly Files ----------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines the enums for the .ll lexer.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_ASMPARSER_LLTOKEN_H
|
| 14 |
+
#define LLVM_ASMPARSER_LLTOKEN_H
|
| 15 |
+
|
| 16 |
+
namespace llvm {
|
| 17 |
+
namespace lltok {
|
| 18 |
+
enum Kind {
|
| 19 |
+
// Markers
|
| 20 |
+
Eof,
|
| 21 |
+
Error,
|
| 22 |
+
|
| 23 |
+
// Tokens with no info.
|
| 24 |
+
dotdotdot, // ...
|
| 25 |
+
equal,
|
| 26 |
+
comma, // = ,
|
| 27 |
+
star, // *
|
| 28 |
+
lsquare,
|
| 29 |
+
rsquare, // [ ]
|
| 30 |
+
lbrace,
|
| 31 |
+
rbrace, // { }
|
| 32 |
+
less,
|
| 33 |
+
greater, // < >
|
| 34 |
+
lparen,
|
| 35 |
+
rparen, // ( )
|
| 36 |
+
exclaim, // !
|
| 37 |
+
bar, // |
|
| 38 |
+
colon, // :
|
| 39 |
+
hash, // #
|
| 40 |
+
|
| 41 |
+
kw_vscale,
|
| 42 |
+
kw_x,
|
| 43 |
+
kw_true,
|
| 44 |
+
kw_false,
|
| 45 |
+
kw_declare,
|
| 46 |
+
kw_define,
|
| 47 |
+
kw_global,
|
| 48 |
+
kw_constant,
|
| 49 |
+
|
| 50 |
+
kw_dso_local,
|
| 51 |
+
kw_dso_preemptable,
|
| 52 |
+
|
| 53 |
+
kw_private,
|
| 54 |
+
kw_internal,
|
| 55 |
+
kw_linkonce,
|
| 56 |
+
kw_linkonce_odr,
|
| 57 |
+
kw_weak, // Used as a linkage, and a modifier for "cmpxchg".
|
| 58 |
+
kw_weak_odr,
|
| 59 |
+
kw_appending,
|
| 60 |
+
kw_dllimport,
|
| 61 |
+
kw_dllexport,
|
| 62 |
+
kw_common,
|
| 63 |
+
kw_available_externally,
|
| 64 |
+
kw_default,
|
| 65 |
+
kw_hidden,
|
| 66 |
+
kw_protected,
|
| 67 |
+
kw_unnamed_addr,
|
| 68 |
+
kw_local_unnamed_addr,
|
| 69 |
+
kw_externally_initialized,
|
| 70 |
+
kw_extern_weak,
|
| 71 |
+
kw_external,
|
| 72 |
+
kw_thread_local,
|
| 73 |
+
kw_localdynamic,
|
| 74 |
+
kw_initialexec,
|
| 75 |
+
kw_localexec,
|
| 76 |
+
kw_zeroinitializer,
|
| 77 |
+
kw_undef,
|
| 78 |
+
kw_poison,
|
| 79 |
+
kw_null,
|
| 80 |
+
kw_none,
|
| 81 |
+
kw_to,
|
| 82 |
+
kw_caller,
|
| 83 |
+
kw_within,
|
| 84 |
+
kw_from,
|
| 85 |
+
kw_tail,
|
| 86 |
+
kw_musttail,
|
| 87 |
+
kw_notail,
|
| 88 |
+
kw_target,
|
| 89 |
+
kw_triple,
|
| 90 |
+
kw_source_filename,
|
| 91 |
+
kw_unwind,
|
| 92 |
+
kw_datalayout,
|
| 93 |
+
kw_volatile,
|
| 94 |
+
kw_atomic,
|
| 95 |
+
kw_unordered,
|
| 96 |
+
kw_monotonic,
|
| 97 |
+
kw_acquire,
|
| 98 |
+
kw_release,
|
| 99 |
+
kw_acq_rel,
|
| 100 |
+
kw_seq_cst,
|
| 101 |
+
kw_syncscope,
|
| 102 |
+
kw_nnan,
|
| 103 |
+
kw_ninf,
|
| 104 |
+
kw_nsz,
|
| 105 |
+
kw_arcp,
|
| 106 |
+
kw_contract,
|
| 107 |
+
kw_reassoc,
|
| 108 |
+
kw_afn,
|
| 109 |
+
kw_fast,
|
| 110 |
+
kw_nuw,
|
| 111 |
+
kw_nsw,
|
| 112 |
+
kw_nusw,
|
| 113 |
+
kw_exact,
|
| 114 |
+
kw_disjoint,
|
| 115 |
+
kw_inbounds,
|
| 116 |
+
kw_nneg,
|
| 117 |
+
kw_samesign,
|
| 118 |
+
kw_inrange,
|
| 119 |
+
kw_addrspace,
|
| 120 |
+
kw_section,
|
| 121 |
+
kw_partition,
|
| 122 |
+
kw_code_model,
|
| 123 |
+
kw_alias,
|
| 124 |
+
kw_ifunc,
|
| 125 |
+
kw_module,
|
| 126 |
+
kw_asm,
|
| 127 |
+
kw_sideeffect,
|
| 128 |
+
kw_inteldialect,
|
| 129 |
+
kw_gc,
|
| 130 |
+
kw_prefix,
|
| 131 |
+
kw_prologue,
|
| 132 |
+
kw_c,
|
| 133 |
+
|
| 134 |
+
kw_cc,
|
| 135 |
+
kw_ccc,
|
| 136 |
+
kw_fastcc,
|
| 137 |
+
kw_coldcc,
|
| 138 |
+
kw_intel_ocl_bicc,
|
| 139 |
+
kw_cfguard_checkcc,
|
| 140 |
+
kw_x86_stdcallcc,
|
| 141 |
+
kw_x86_fastcallcc,
|
| 142 |
+
kw_x86_thiscallcc,
|
| 143 |
+
kw_x86_vectorcallcc,
|
| 144 |
+
kw_x86_regcallcc,
|
| 145 |
+
kw_arm_apcscc,
|
| 146 |
+
kw_arm_aapcscc,
|
| 147 |
+
kw_arm_aapcs_vfpcc,
|
| 148 |
+
kw_aarch64_vector_pcs,
|
| 149 |
+
kw_aarch64_sve_vector_pcs,
|
| 150 |
+
kw_aarch64_sme_preservemost_from_x0,
|
| 151 |
+
kw_aarch64_sme_preservemost_from_x1,
|
| 152 |
+
kw_aarch64_sme_preservemost_from_x2,
|
| 153 |
+
kw_msp430_intrcc,
|
| 154 |
+
kw_avr_intrcc,
|
| 155 |
+
kw_avr_signalcc,
|
| 156 |
+
kw_ptx_kernel,
|
| 157 |
+
kw_ptx_device,
|
| 158 |
+
kw_spir_kernel,
|
| 159 |
+
kw_spir_func,
|
| 160 |
+
kw_x86_64_sysvcc,
|
| 161 |
+
kw_win64cc,
|
| 162 |
+
kw_anyregcc,
|
| 163 |
+
kw_swiftcc,
|
| 164 |
+
kw_swifttailcc,
|
| 165 |
+
kw_preserve_mostcc,
|
| 166 |
+
kw_preserve_allcc,
|
| 167 |
+
kw_preserve_nonecc,
|
| 168 |
+
kw_ghccc,
|
| 169 |
+
kw_x86_intrcc,
|
| 170 |
+
kw_hhvmcc,
|
| 171 |
+
kw_hhvm_ccc,
|
| 172 |
+
kw_cxx_fast_tlscc,
|
| 173 |
+
kw_amdgpu_vs,
|
| 174 |
+
kw_amdgpu_ls,
|
| 175 |
+
kw_amdgpu_hs,
|
| 176 |
+
kw_amdgpu_es,
|
| 177 |
+
kw_amdgpu_gs,
|
| 178 |
+
kw_amdgpu_ps,
|
| 179 |
+
kw_amdgpu_cs,
|
| 180 |
+
kw_amdgpu_cs_chain,
|
| 181 |
+
kw_amdgpu_cs_chain_preserve,
|
| 182 |
+
kw_amdgpu_kernel,
|
| 183 |
+
kw_amdgpu_gfx,
|
| 184 |
+
kw_tailcc,
|
| 185 |
+
kw_m68k_rtdcc,
|
| 186 |
+
kw_graalcc,
|
| 187 |
+
kw_riscv_vector_cc,
|
| 188 |
+
kw_riscv_vls_cc,
|
| 189 |
+
|
| 190 |
+
// Attributes:
|
| 191 |
+
kw_attributes,
|
| 192 |
+
kw_sync,
|
| 193 |
+
kw_async,
|
| 194 |
+
#define GET_ATTR_NAMES
|
| 195 |
+
#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
|
| 196 |
+
kw_##DISPLAY_NAME,
|
| 197 |
+
#include "llvm/IR/Attributes.inc"
|
| 198 |
+
|
| 199 |
+
// Memory attribute:
|
| 200 |
+
kw_read,
|
| 201 |
+
kw_write,
|
| 202 |
+
kw_readwrite,
|
| 203 |
+
kw_argmem,
|
| 204 |
+
kw_inaccessiblemem,
|
| 205 |
+
kw_errnomem,
|
| 206 |
+
|
| 207 |
+
// Legacy attributes:
|
| 208 |
+
kw_argmemonly,
|
| 209 |
+
kw_inaccessiblememonly,
|
| 210 |
+
kw_inaccessiblemem_or_argmemonly,
|
| 211 |
+
kw_nocapture,
|
| 212 |
+
|
| 213 |
+
// Captures attribute:
|
| 214 |
+
kw_address,
|
| 215 |
+
kw_address_is_null,
|
| 216 |
+
kw_provenance,
|
| 217 |
+
kw_read_provenance,
|
| 218 |
+
|
| 219 |
+
// nofpclass attribute:
|
| 220 |
+
kw_all,
|
| 221 |
+
kw_nan,
|
| 222 |
+
kw_snan,
|
| 223 |
+
kw_qnan,
|
| 224 |
+
kw_inf,
|
| 225 |
+
// kw_ninf, - already an fmf
|
| 226 |
+
kw_pinf,
|
| 227 |
+
kw_norm,
|
| 228 |
+
kw_nnorm,
|
| 229 |
+
kw_pnorm,
|
| 230 |
+
// kw_sub, - already an instruction
|
| 231 |
+
kw_nsub,
|
| 232 |
+
kw_psub,
|
| 233 |
+
kw_zero,
|
| 234 |
+
kw_nzero,
|
| 235 |
+
kw_pzero,
|
| 236 |
+
|
| 237 |
+
kw_type,
|
| 238 |
+
kw_opaque,
|
| 239 |
+
|
| 240 |
+
kw_comdat,
|
| 241 |
+
|
| 242 |
+
// Comdat types
|
| 243 |
+
kw_any,
|
| 244 |
+
kw_exactmatch,
|
| 245 |
+
kw_largest,
|
| 246 |
+
kw_nodeduplicate,
|
| 247 |
+
kw_samesize,
|
| 248 |
+
|
| 249 |
+
kw_eq,
|
| 250 |
+
kw_ne,
|
| 251 |
+
kw_slt,
|
| 252 |
+
kw_sgt,
|
| 253 |
+
kw_sle,
|
| 254 |
+
kw_sge,
|
| 255 |
+
kw_ult,
|
| 256 |
+
kw_ugt,
|
| 257 |
+
kw_ule,
|
| 258 |
+
kw_uge,
|
| 259 |
+
kw_oeq,
|
| 260 |
+
kw_one,
|
| 261 |
+
kw_olt,
|
| 262 |
+
kw_ogt,
|
| 263 |
+
kw_ole,
|
| 264 |
+
kw_oge,
|
| 265 |
+
kw_ord,
|
| 266 |
+
kw_uno,
|
| 267 |
+
kw_ueq,
|
| 268 |
+
kw_une,
|
| 269 |
+
|
| 270 |
+
// atomicrmw operations that aren't also instruction keywords.
|
| 271 |
+
kw_xchg,
|
| 272 |
+
kw_nand,
|
| 273 |
+
kw_max,
|
| 274 |
+
kw_min,
|
| 275 |
+
kw_umax,
|
| 276 |
+
kw_umin,
|
| 277 |
+
kw_fmax,
|
| 278 |
+
kw_fmin,
|
| 279 |
+
kw_fmaximum,
|
| 280 |
+
kw_fminimum,
|
| 281 |
+
kw_uinc_wrap,
|
| 282 |
+
kw_udec_wrap,
|
| 283 |
+
kw_usub_cond,
|
| 284 |
+
kw_usub_sat,
|
| 285 |
+
|
| 286 |
+
// Instruction Opcodes (Opcode in UIntVal).
|
| 287 |
+
kw_fneg,
|
| 288 |
+
kw_add,
|
| 289 |
+
kw_fadd,
|
| 290 |
+
kw_sub,
|
| 291 |
+
kw_fsub,
|
| 292 |
+
kw_mul,
|
| 293 |
+
kw_fmul,
|
| 294 |
+
kw_udiv,
|
| 295 |
+
kw_sdiv,
|
| 296 |
+
kw_fdiv,
|
| 297 |
+
kw_urem,
|
| 298 |
+
kw_srem,
|
| 299 |
+
kw_frem,
|
| 300 |
+
kw_shl,
|
| 301 |
+
kw_lshr,
|
| 302 |
+
kw_ashr,
|
| 303 |
+
kw_and,
|
| 304 |
+
kw_or,
|
| 305 |
+
kw_xor,
|
| 306 |
+
kw_icmp,
|
| 307 |
+
kw_fcmp,
|
| 308 |
+
|
| 309 |
+
kw_phi,
|
| 310 |
+
kw_call,
|
| 311 |
+
kw_trunc,
|
| 312 |
+
kw_zext,
|
| 313 |
+
kw_sext,
|
| 314 |
+
kw_fptrunc,
|
| 315 |
+
kw_fpext,
|
| 316 |
+
kw_uitofp,
|
| 317 |
+
kw_sitofp,
|
| 318 |
+
kw_fptoui,
|
| 319 |
+
kw_fptosi,
|
| 320 |
+
kw_inttoptr,
|
| 321 |
+
kw_ptrtoint,
|
| 322 |
+
kw_bitcast,
|
| 323 |
+
kw_addrspacecast,
|
| 324 |
+
kw_select,
|
| 325 |
+
kw_va_arg,
|
| 326 |
+
|
| 327 |
+
kw_landingpad,
|
| 328 |
+
kw_personality,
|
| 329 |
+
kw_cleanup,
|
| 330 |
+
kw_catch,
|
| 331 |
+
kw_filter,
|
| 332 |
+
|
| 333 |
+
kw_ret,
|
| 334 |
+
kw_br,
|
| 335 |
+
kw_switch,
|
| 336 |
+
kw_indirectbr,
|
| 337 |
+
kw_invoke,
|
| 338 |
+
kw_resume,
|
| 339 |
+
kw_unreachable,
|
| 340 |
+
kw_cleanupret,
|
| 341 |
+
kw_catchswitch,
|
| 342 |
+
kw_catchret,
|
| 343 |
+
kw_catchpad,
|
| 344 |
+
kw_cleanuppad,
|
| 345 |
+
kw_callbr,
|
| 346 |
+
|
| 347 |
+
kw_alloca,
|
| 348 |
+
kw_load,
|
| 349 |
+
kw_store,
|
| 350 |
+
kw_fence,
|
| 351 |
+
kw_cmpxchg,
|
| 352 |
+
kw_atomicrmw,
|
| 353 |
+
kw_getelementptr,
|
| 354 |
+
|
| 355 |
+
kw_extractelement,
|
| 356 |
+
kw_insertelement,
|
| 357 |
+
kw_shufflevector,
|
| 358 |
+
kw_splat,
|
| 359 |
+
kw_extractvalue,
|
| 360 |
+
kw_insertvalue,
|
| 361 |
+
kw_blockaddress,
|
| 362 |
+
kw_dso_local_equivalent,
|
| 363 |
+
kw_no_cfi,
|
| 364 |
+
kw_ptrauth,
|
| 365 |
+
|
| 366 |
+
kw_freeze,
|
| 367 |
+
|
| 368 |
+
// Metadata types.
|
| 369 |
+
kw_distinct,
|
| 370 |
+
|
| 371 |
+
// Use-list order directives.
|
| 372 |
+
kw_uselistorder,
|
| 373 |
+
kw_uselistorder_bb,
|
| 374 |
+
|
| 375 |
+
// Summary index keywords
|
| 376 |
+
kw_path,
|
| 377 |
+
kw_hash,
|
| 378 |
+
kw_gv,
|
| 379 |
+
kw_guid,
|
| 380 |
+
kw_name,
|
| 381 |
+
kw_summaries,
|
| 382 |
+
kw_flags,
|
| 383 |
+
kw_blockcount,
|
| 384 |
+
kw_linkage,
|
| 385 |
+
kw_visibility,
|
| 386 |
+
kw_notEligibleToImport,
|
| 387 |
+
kw_live,
|
| 388 |
+
kw_dsoLocal,
|
| 389 |
+
kw_canAutoHide,
|
| 390 |
+
kw_importType,
|
| 391 |
+
kw_definition,
|
| 392 |
+
kw_declaration,
|
| 393 |
+
kw_function,
|
| 394 |
+
kw_insts,
|
| 395 |
+
kw_funcFlags,
|
| 396 |
+
kw_readNone,
|
| 397 |
+
kw_readOnly,
|
| 398 |
+
kw_noRecurse,
|
| 399 |
+
kw_returnDoesNotAlias,
|
| 400 |
+
kw_noInline,
|
| 401 |
+
kw_alwaysInline,
|
| 402 |
+
kw_noUnwind,
|
| 403 |
+
kw_mayThrow,
|
| 404 |
+
kw_hasUnknownCall,
|
| 405 |
+
kw_mustBeUnreachable,
|
| 406 |
+
kw_calls,
|
| 407 |
+
kw_callee,
|
| 408 |
+
kw_params,
|
| 409 |
+
kw_param,
|
| 410 |
+
kw_hotness,
|
| 411 |
+
kw_unknown,
|
| 412 |
+
kw_critical,
|
| 413 |
+
kw_relbf,
|
| 414 |
+
kw_variable,
|
| 415 |
+
kw_vTableFuncs,
|
| 416 |
+
kw_virtFunc,
|
| 417 |
+
kw_aliasee,
|
| 418 |
+
kw_refs,
|
| 419 |
+
kw_typeIdInfo,
|
| 420 |
+
kw_typeTests,
|
| 421 |
+
kw_typeTestAssumeVCalls,
|
| 422 |
+
kw_typeCheckedLoadVCalls,
|
| 423 |
+
kw_typeTestAssumeConstVCalls,
|
| 424 |
+
kw_typeCheckedLoadConstVCalls,
|
| 425 |
+
kw_vFuncId,
|
| 426 |
+
kw_offset,
|
| 427 |
+
kw_args,
|
| 428 |
+
kw_typeid,
|
| 429 |
+
kw_typeidCompatibleVTable,
|
| 430 |
+
kw_summary,
|
| 431 |
+
kw_typeTestRes,
|
| 432 |
+
kw_kind,
|
| 433 |
+
kw_unsat,
|
| 434 |
+
kw_byteArray,
|
| 435 |
+
kw_inline,
|
| 436 |
+
kw_single,
|
| 437 |
+
kw_allOnes,
|
| 438 |
+
kw_sizeM1BitWidth,
|
| 439 |
+
kw_alignLog2,
|
| 440 |
+
kw_sizeM1,
|
| 441 |
+
kw_bitMask,
|
| 442 |
+
kw_inlineBits,
|
| 443 |
+
kw_vcall_visibility,
|
| 444 |
+
kw_wpdResolutions,
|
| 445 |
+
kw_wpdRes,
|
| 446 |
+
kw_indir,
|
| 447 |
+
kw_singleImpl,
|
| 448 |
+
kw_branchFunnel,
|
| 449 |
+
kw_singleImplName,
|
| 450 |
+
kw_resByArg,
|
| 451 |
+
kw_byArg,
|
| 452 |
+
kw_uniformRetVal,
|
| 453 |
+
kw_uniqueRetVal,
|
| 454 |
+
kw_virtualConstProp,
|
| 455 |
+
kw_info,
|
| 456 |
+
kw_byte,
|
| 457 |
+
kw_bit,
|
| 458 |
+
kw_varFlags,
|
| 459 |
+
// The following are used by MemProf summary info.
|
| 460 |
+
kw_callsites,
|
| 461 |
+
kw_clones,
|
| 462 |
+
kw_stackIds,
|
| 463 |
+
kw_allocs,
|
| 464 |
+
kw_versions,
|
| 465 |
+
kw_memProf,
|
| 466 |
+
kw_notcold,
|
| 467 |
+
|
| 468 |
+
// GV's with __attribute__((no_sanitize("address"))), or things in
|
| 469 |
+
// -fsanitize-ignorelist when built with ASan.
|
| 470 |
+
kw_no_sanitize_address,
|
| 471 |
+
// GV's with __attribute__((no_sanitize("hwaddress"))), or things in
|
| 472 |
+
// -fsanitize-ignorelist when built with HWASan.
|
| 473 |
+
kw_no_sanitize_hwaddress,
|
| 474 |
+
// GV's where the clang++ frontend (when ASan is used) notes that this is
|
| 475 |
+
// dynamically initialized, and thus needs ODR detection.
|
| 476 |
+
kw_sanitize_address_dyninit,
|
| 477 |
+
|
| 478 |
+
// Unsigned Valued tokens (UIntVal).
|
| 479 |
+
LabelID, // 42:
|
| 480 |
+
GlobalID, // @42
|
| 481 |
+
LocalVarID, // %42
|
| 482 |
+
AttrGrpID, // #42
|
| 483 |
+
SummaryID, // ^42
|
| 484 |
+
|
| 485 |
+
// String valued tokens (StrVal).
|
| 486 |
+
LabelStr, // foo:
|
| 487 |
+
GlobalVar, // @foo @"foo"
|
| 488 |
+
ComdatVar, // $foo
|
| 489 |
+
LocalVar, // %foo %"foo"
|
| 490 |
+
MetadataVar, // !foo
|
| 491 |
+
StringConstant, // "foo"
|
| 492 |
+
DwarfTag, // DW_TAG_foo
|
| 493 |
+
DwarfAttEncoding, // DW_ATE_foo
|
| 494 |
+
DwarfVirtuality, // DW_VIRTUALITY_foo
|
| 495 |
+
DwarfLang, // DW_LANG_foo
|
| 496 |
+
DwarfCC, // DW_CC_foo
|
| 497 |
+
EmissionKind, // lineTablesOnly
|
| 498 |
+
NameTableKind, // GNU
|
| 499 |
+
FixedPointKind, // Fixed point
|
| 500 |
+
DwarfOp, // DW_OP_foo
|
| 501 |
+
DIFlag, // DIFlagFoo
|
| 502 |
+
DISPFlag, // DISPFlagFoo
|
| 503 |
+
DwarfMacinfo, // DW_MACINFO_foo
|
| 504 |
+
ChecksumKind, // CSK_foo
|
| 505 |
+
DbgRecordType, // dbg_foo
|
| 506 |
+
DwarfEnumKind, // DW_APPLE_ENUM_KIND_foo
|
| 507 |
+
|
| 508 |
+
// Type valued tokens (TyVal).
|
| 509 |
+
Type,
|
| 510 |
+
|
| 511 |
+
APFloat, // APFloatVal
|
| 512 |
+
APSInt // APSInt
|
| 513 |
+
};
|
| 514 |
+
} // end namespace lltok
|
| 515 |
+
} // end namespace llvm
|
| 516 |
+
|
| 517 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/AsmParser/NumberedValues.h
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- NumberedValues.h - --------------------------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
|
| 9 |
+
#ifndef LLVM_ASMPARSER_NUMBEREDVALUES_H
|
| 10 |
+
#define LLVM_ASMPARSER_NUMBEREDVALUES_H
|
| 11 |
+
|
| 12 |
+
#include "llvm/ADT/DenseMap.h"
|
| 13 |
+
|
| 14 |
+
namespace llvm {
|
| 15 |
+
|
| 16 |
+
/// Mapping from value ID to value, which also remembers what the next unused
|
| 17 |
+
/// ID is.
|
| 18 |
+
template <class T> class NumberedValues {
|
| 19 |
+
DenseMap<unsigned, T> Vals;
|
| 20 |
+
unsigned NextUnusedID = 0;
|
| 21 |
+
|
| 22 |
+
public:
|
| 23 |
+
unsigned getNext() const { return NextUnusedID; }
|
| 24 |
+
T get(unsigned ID) const { return Vals.lookup(ID); }
|
| 25 |
+
void add(unsigned ID, T V) {
|
| 26 |
+
assert(ID >= NextUnusedID && "Invalid value ID");
|
| 27 |
+
Vals.insert({ID, V});
|
| 28 |
+
NextUnusedID = ID + 1;
|
| 29 |
+
}
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
} // end namespace llvm
|
| 33 |
+
|
| 34 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/AsmParser/Parser.h
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- Parser.h - Parser for LLVM IR text assembly files -------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// These classes are implemented by the lib/AsmParser library.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_ASMPARSER_PARSER_H
|
| 14 |
+
#define LLVM_ASMPARSER_PARSER_H
|
| 15 |
+
|
| 16 |
+
#include "llvm/ADT/STLFunctionalExtras.h"
|
| 17 |
+
#include "llvm/ADT/StringRef.h"
|
| 18 |
+
#include "llvm/Support/Compiler.h"
|
| 19 |
+
#include <memory>
|
| 20 |
+
#include <optional>
|
| 21 |
+
|
| 22 |
+
namespace llvm {
|
| 23 |
+
|
| 24 |
+
class Constant;
|
| 25 |
+
class DIExpression;
|
| 26 |
+
class LLVMContext;
|
| 27 |
+
class MemoryBufferRef;
|
| 28 |
+
class Module;
|
| 29 |
+
class ModuleSummaryIndex;
|
| 30 |
+
struct SlotMapping;
|
| 31 |
+
class SMDiagnostic;
|
| 32 |
+
class Type;
|
| 33 |
+
|
| 34 |
+
typedef llvm::function_ref<std::optional<std::string>(StringRef, StringRef)>
|
| 35 |
+
DataLayoutCallbackTy;
|
| 36 |
+
|
| 37 |
+
/// This function is a main interface to the LLVM Assembly Parser. It parses
|
| 38 |
+
/// an ASCII file that (presumably) contains LLVM Assembly code. It returns a
|
| 39 |
+
/// Module (intermediate representation) with the corresponding features. Note
|
| 40 |
+
/// that this does not verify that the generated Module is valid, so you should
|
| 41 |
+
/// run the verifier after parsing the file to check that it is okay.
|
| 42 |
+
/// Parse LLVM Assembly from a file
|
| 43 |
+
/// \param Filename The name of the file to parse
|
| 44 |
+
/// \param Err Error result info.
|
| 45 |
+
/// \param Context Context in which to allocate globals info.
|
| 46 |
+
/// \param Slots The optional slot mapping that will be initialized during
|
| 47 |
+
/// parsing.
|
| 48 |
+
LLVM_ABI std::unique_ptr<Module>
|
| 49 |
+
parseAssemblyFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
|
| 50 |
+
SlotMapping *Slots = nullptr);
|
| 51 |
+
|
| 52 |
+
/// The function is a secondary interface to the LLVM Assembly Parser. It parses
|
| 53 |
+
/// an ASCII string that (presumably) contains LLVM Assembly code. It returns a
|
| 54 |
+
/// Module (intermediate representation) with the corresponding features. Note
|
| 55 |
+
/// that this does not verify that the generated Module is valid, so you should
|
| 56 |
+
/// run the verifier after parsing the file to check that it is okay.
|
| 57 |
+
/// Parse LLVM Assembly from a string
|
| 58 |
+
/// \param AsmString The string containing assembly
|
| 59 |
+
/// \param Err Error result info.
|
| 60 |
+
/// \param Context Context in which to allocate globals info.
|
| 61 |
+
/// \param Slots The optional slot mapping that will be initialized during
|
| 62 |
+
/// parsing.
|
| 63 |
+
LLVM_ABI std::unique_ptr<Module>
|
| 64 |
+
parseAssemblyString(StringRef AsmString, SMDiagnostic &Err,
|
| 65 |
+
LLVMContext &Context, SlotMapping *Slots = nullptr);
|
| 66 |
+
|
| 67 |
+
/// Holds the Module and ModuleSummaryIndex returned by the interfaces
|
| 68 |
+
/// that parse both.
|
| 69 |
+
struct ParsedModuleAndIndex {
|
| 70 |
+
std::unique_ptr<Module> Mod;
|
| 71 |
+
std::unique_ptr<ModuleSummaryIndex> Index;
|
| 72 |
+
};
|
| 73 |
+
|
| 74 |
+
/// This function is a main interface to the LLVM Assembly Parser. It parses
|
| 75 |
+
/// an ASCII file that (presumably) contains LLVM Assembly code, including
|
| 76 |
+
/// a module summary. It returns a Module (intermediate representation) and
|
| 77 |
+
/// a ModuleSummaryIndex with the corresponding features. Note that this does
|
| 78 |
+
/// not verify that the generated Module or Index are valid, so you should
|
| 79 |
+
/// run the verifier after parsing the file to check that they are okay.
|
| 80 |
+
/// Parse LLVM Assembly from a file
|
| 81 |
+
/// \param Filename The name of the file to parse
|
| 82 |
+
/// \param Err Error result info.
|
| 83 |
+
/// \param Context Context in which to allocate globals info.
|
| 84 |
+
/// \param Slots The optional slot mapping that will be initialized during
|
| 85 |
+
/// parsing.
|
| 86 |
+
/// \param DataLayoutCallback Override datalayout in the llvm assembly.
|
| 87 |
+
LLVM_ABI ParsedModuleAndIndex parseAssemblyFileWithIndex(
|
| 88 |
+
StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
|
| 89 |
+
SlotMapping *Slots = nullptr,
|
| 90 |
+
DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) {
|
| 91 |
+
return std::nullopt;
|
| 92 |
+
});
|
| 93 |
+
|
| 94 |
+
/// Only for use in llvm-as for testing; this does not produce a valid module.
|
| 95 |
+
LLVM_ABI ParsedModuleAndIndex parseAssemblyFileWithIndexNoUpgradeDebugInfo(
|
| 96 |
+
StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
|
| 97 |
+
SlotMapping *Slots, DataLayoutCallbackTy DataLayoutCallback);
|
| 98 |
+
|
| 99 |
+
/// This function is a main interface to the LLVM Assembly Parser. It parses
|
| 100 |
+
/// an ASCII file that (presumably) contains LLVM Assembly code for a module
|
| 101 |
+
/// summary. It returns a ModuleSummaryIndex with the corresponding features.
|
| 102 |
+
/// Note that this does not verify that the generated Index is valid, so you
|
| 103 |
+
/// should run the verifier after parsing the file to check that it is okay.
|
| 104 |
+
/// Parse LLVM Assembly Index from a file
|
| 105 |
+
/// \param Filename The name of the file to parse
|
| 106 |
+
/// \param Err Error result info.
|
| 107 |
+
LLVM_ABI std::unique_ptr<ModuleSummaryIndex>
|
| 108 |
+
parseSummaryIndexAssemblyFile(StringRef Filename, SMDiagnostic &Err);
|
| 109 |
+
|
| 110 |
+
/// The function is a secondary interface to the LLVM Assembly Parser. It parses
|
| 111 |
+
/// an ASCII string that (presumably) contains LLVM Assembly code for a module
|
| 112 |
+
/// summary. It returns a a ModuleSummaryIndex with the corresponding features.
|
| 113 |
+
/// Note that this does not verify that the generated Index is valid, so you
|
| 114 |
+
/// should run the verifier after parsing the file to check that it is okay.
|
| 115 |
+
/// Parse LLVM Assembly from a string
|
| 116 |
+
/// \param AsmString The string containing assembly
|
| 117 |
+
/// \param Err Error result info.
|
| 118 |
+
LLVM_ABI std::unique_ptr<ModuleSummaryIndex>
|
| 119 |
+
parseSummaryIndexAssemblyString(StringRef AsmString, SMDiagnostic &Err);
|
| 120 |
+
|
| 121 |
+
/// parseAssemblyFile and parseAssemblyString are wrappers around this function.
|
| 122 |
+
/// Parse LLVM Assembly from a MemoryBuffer.
|
| 123 |
+
/// \param F The MemoryBuffer containing assembly
|
| 124 |
+
/// \param Err Error result info.
|
| 125 |
+
/// \param Slots The optional slot mapping that will be initialized during
|
| 126 |
+
/// parsing.
|
| 127 |
+
/// \param DataLayoutCallback Override datalayout in the llvm assembly.
|
| 128 |
+
LLVM_ABI std::unique_ptr<Module> parseAssembly(
|
| 129 |
+
MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context,
|
| 130 |
+
SlotMapping *Slots = nullptr,
|
| 131 |
+
DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) {
|
| 132 |
+
return std::nullopt;
|
| 133 |
+
});
|
| 134 |
+
|
| 135 |
+
/// Parse LLVM Assembly including the summary index from a MemoryBuffer.
|
| 136 |
+
///
|
| 137 |
+
/// \param F The MemoryBuffer containing assembly with summary
|
| 138 |
+
/// \param Err Error result info.
|
| 139 |
+
/// \param Slots The optional slot mapping that will be initialized during
|
| 140 |
+
/// parsing.
|
| 141 |
+
///
|
| 142 |
+
/// parseAssemblyFileWithIndex is a wrapper around this function.
|
| 143 |
+
LLVM_ABI ParsedModuleAndIndex
|
| 144 |
+
parseAssemblyWithIndex(MemoryBufferRef F, SMDiagnostic &Err,
|
| 145 |
+
LLVMContext &Context, SlotMapping *Slots = nullptr);
|
| 146 |
+
|
| 147 |
+
/// Parse LLVM Assembly for summary index from a MemoryBuffer.
|
| 148 |
+
///
|
| 149 |
+
/// \param F The MemoryBuffer containing assembly with summary
|
| 150 |
+
/// \param Err Error result info.
|
| 151 |
+
///
|
| 152 |
+
/// parseSummaryIndexAssemblyFile is a wrapper around this function.
|
| 153 |
+
LLVM_ABI std::unique_ptr<ModuleSummaryIndex>
|
| 154 |
+
parseSummaryIndexAssembly(MemoryBufferRef F, SMDiagnostic &Err);
|
| 155 |
+
|
| 156 |
+
/// This function is the low-level interface to the LLVM Assembly Parser.
|
| 157 |
+
/// This is kept as an independent function instead of being inlined into
|
| 158 |
+
/// parseAssembly for the convenience of interactive users that want to add
|
| 159 |
+
/// recently parsed bits to an existing module.
|
| 160 |
+
///
|
| 161 |
+
/// \param F The MemoryBuffer containing assembly
|
| 162 |
+
/// \param M The module to add data to.
|
| 163 |
+
/// \param Index The index to add data to.
|
| 164 |
+
/// \param Err Error result info.
|
| 165 |
+
/// \param Slots The optional slot mapping that will be initialized during
|
| 166 |
+
/// parsing.
|
| 167 |
+
/// \return true on error.
|
| 168 |
+
/// \param DataLayoutCallback Override datalayout in the llvm assembly.
|
| 169 |
+
LLVM_ABI bool parseAssemblyInto(
|
| 170 |
+
MemoryBufferRef F, Module *M, ModuleSummaryIndex *Index, SMDiagnostic &Err,
|
| 171 |
+
SlotMapping *Slots = nullptr,
|
| 172 |
+
DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) {
|
| 173 |
+
return std::nullopt;
|
| 174 |
+
});
|
| 175 |
+
|
| 176 |
+
/// Parse a type and a constant value in the given string.
|
| 177 |
+
///
|
| 178 |
+
/// The constant value can be any LLVM constant, including a constant
|
| 179 |
+
/// expression.
|
| 180 |
+
///
|
| 181 |
+
/// \param Slots The optional slot mapping that will restore the parsing state
|
| 182 |
+
/// of the module.
|
| 183 |
+
/// \return null on error.
|
| 184 |
+
LLVM_ABI Constant *parseConstantValue(StringRef Asm, SMDiagnostic &Err,
|
| 185 |
+
const Module &M,
|
| 186 |
+
const SlotMapping *Slots = nullptr);
|
| 187 |
+
|
| 188 |
+
/// Parse a type in the given string.
|
| 189 |
+
///
|
| 190 |
+
/// \param Slots The optional slot mapping that will restore the parsing state
|
| 191 |
+
/// of the module.
|
| 192 |
+
/// \return null on error.
|
| 193 |
+
LLVM_ABI Type *parseType(StringRef Asm, SMDiagnostic &Err, const Module &M,
|
| 194 |
+
const SlotMapping *Slots = nullptr);
|
| 195 |
+
|
| 196 |
+
/// Parse a string \p Asm that starts with a type.
|
| 197 |
+
/// \p Read[out] gives the number of characters that have been read to parse
|
| 198 |
+
/// the type in \p Asm.
|
| 199 |
+
///
|
| 200 |
+
/// \param Slots The optional slot mapping that will restore the parsing state
|
| 201 |
+
/// of the module.
|
| 202 |
+
/// \return null on error.
|
| 203 |
+
LLVM_ABI Type *parseTypeAtBeginning(StringRef Asm, unsigned &Read,
|
| 204 |
+
SMDiagnostic &Err, const Module &M,
|
| 205 |
+
const SlotMapping *Slots = nullptr);
|
| 206 |
+
|
| 207 |
+
LLVM_ABI DIExpression *
|
| 208 |
+
parseDIExpressionBodyAtBeginning(StringRef Asm, unsigned &Read,
|
| 209 |
+
SMDiagnostic &Err, const Module &M,
|
| 210 |
+
const SlotMapping *Slots);
|
| 211 |
+
|
| 212 |
+
} // End llvm namespace
|
| 213 |
+
|
| 214 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/AsmParser/SlotMapping.h
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- SlotMapping.h - Slot number mapping for unnamed values --*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file contains the declaration of the SlotMapping struct.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_ASMPARSER_SLOTMAPPING_H
|
| 14 |
+
#define LLVM_ASMPARSER_SLOTMAPPING_H
|
| 15 |
+
|
| 16 |
+
#include "llvm/ADT/StringMap.h"
|
| 17 |
+
#include "llvm/AsmParser/NumberedValues.h"
|
| 18 |
+
#include "llvm/IR/TrackingMDRef.h"
|
| 19 |
+
#include <map>
|
| 20 |
+
#include <vector>
|
| 21 |
+
|
| 22 |
+
namespace llvm {
|
| 23 |
+
|
| 24 |
+
class GlobalValue;
|
| 25 |
+
class Type;
|
| 26 |
+
|
| 27 |
+
/// This struct contains the mappings from the slot numbers to unnamed metadata
|
| 28 |
+
/// nodes, global values and types. It also contains the mapping for the named
|
| 29 |
+
/// types.
|
| 30 |
+
/// It can be used to save the parsing state of an LLVM IR module so that the
|
| 31 |
+
/// textual references to the values in the module can be parsed outside of the
|
| 32 |
+
/// module's source.
|
| 33 |
+
struct SlotMapping {
|
| 34 |
+
NumberedValues<GlobalValue *> GlobalValues;
|
| 35 |
+
std::map<unsigned, TrackingMDNodeRef> MetadataNodes;
|
| 36 |
+
StringMap<Type *> NamedTypes;
|
| 37 |
+
std::map<unsigned, Type *> Types;
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
} // end namespace llvm
|
| 41 |
+
|
| 42 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Debuginfod/BuildIDFetcher.h
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/DebugInfod/BuildIDFetcher.h - Build ID fetcher ------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
///
|
| 9 |
+
/// \file
|
| 10 |
+
/// This file declares a Build ID fetcher implementation for obtaining debug
|
| 11 |
+
/// info from debuginfod.
|
| 12 |
+
///
|
| 13 |
+
//===----------------------------------------------------------------------===//
|
| 14 |
+
|
| 15 |
+
#ifndef LLVM_DEBUGINFOD_DIFETCHER_H
|
| 16 |
+
#define LLVM_DEBUGINFOD_DIFETCHER_H
|
| 17 |
+
|
| 18 |
+
#include "llvm/Object/BuildID.h"
|
| 19 |
+
#include <optional>
|
| 20 |
+
|
| 21 |
+
namespace llvm {
|
| 22 |
+
|
| 23 |
+
class DebuginfodFetcher : public object::BuildIDFetcher {
|
| 24 |
+
public:
|
| 25 |
+
DebuginfodFetcher(std::vector<std::string> DebugFileDirectories)
|
| 26 |
+
: BuildIDFetcher(std::move(DebugFileDirectories)) {}
|
| 27 |
+
virtual ~DebuginfodFetcher() = default;
|
| 28 |
+
|
| 29 |
+
/// Fetches the given Build ID using debuginfod and returns a local path to
|
| 30 |
+
/// the resulting file.
|
| 31 |
+
std::optional<std::string> fetch(object::BuildIDRef BuildID) const override;
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
} // namespace llvm
|
| 35 |
+
|
| 36 |
+
#endif // LLVM_DEBUGINFOD_DIFETCHER_H
|
deps/exla/cache/xla_extension/include/llvm/Debuginfod/Debuginfod.h
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- llvm/Debuginfod/Debuginfod.h - Debuginfod client --------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
///
|
| 9 |
+
/// \file
|
| 10 |
+
/// This file contains several declarations for the debuginfod client and
|
| 11 |
+
/// server. The client functions are getDefaultDebuginfodUrls,
|
| 12 |
+
/// getCachedOrDownloadArtifact, and several convenience functions for specific
|
| 13 |
+
/// artifact types: getCachedOrDownloadSource, getCachedOrDownloadExecutable,
|
| 14 |
+
/// and getCachedOrDownloadDebuginfo. For the server, this file declares the
|
| 15 |
+
/// DebuginfodLogEntry and DebuginfodServer structs, as well as the
|
| 16 |
+
/// DebuginfodLog, DebuginfodCollection classes.
|
| 17 |
+
///
|
| 18 |
+
//===----------------------------------------------------------------------===//
|
| 19 |
+
|
| 20 |
+
#ifndef LLVM_DEBUGINFOD_DEBUGINFOD_H
|
| 21 |
+
#define LLVM_DEBUGINFOD_DEBUGINFOD_H
|
| 22 |
+
|
| 23 |
+
#include "HTTPServer.h"
|
| 24 |
+
|
| 25 |
+
#include "llvm/ADT/StringMap.h"
|
| 26 |
+
#include "llvm/ADT/StringRef.h"
|
| 27 |
+
#include "llvm/Object/BuildID.h"
|
| 28 |
+
#include "llvm/Support/Error.h"
|
| 29 |
+
#include "llvm/Support/MemoryBuffer.h"
|
| 30 |
+
#include "llvm/Support/Mutex.h"
|
| 31 |
+
#include "llvm/Support/RWMutex.h"
|
| 32 |
+
#include "llvm/Support/Timer.h"
|
| 33 |
+
|
| 34 |
+
#include <chrono>
|
| 35 |
+
#include <condition_variable>
|
| 36 |
+
#include <optional>
|
| 37 |
+
#include <queue>
|
| 38 |
+
|
| 39 |
+
namespace llvm {
|
| 40 |
+
|
| 41 |
+
/// Returns false if a debuginfod lookup can be determined to have no chance of
|
| 42 |
+
/// succeeding.
|
| 43 |
+
bool canUseDebuginfod();
|
| 44 |
+
|
| 45 |
+
/// Finds default array of Debuginfod server URLs by checking DEBUGINFOD_URLS
|
| 46 |
+
/// environment variable.
|
| 47 |
+
SmallVector<StringRef> getDefaultDebuginfodUrls();
|
| 48 |
+
|
| 49 |
+
/// Returns the cache key for a given debuginfod URL path.
|
| 50 |
+
std::string getDebuginfodCacheKey(StringRef UrlPath);
|
| 51 |
+
|
| 52 |
+
/// Sets the list of debuginfod server URLs to query. This overrides the
|
| 53 |
+
/// environment variable DEBUGINFOD_URLS.
|
| 54 |
+
void setDefaultDebuginfodUrls(const SmallVector<StringRef> &URLs);
|
| 55 |
+
|
| 56 |
+
/// Finds a default local file caching directory for the debuginfod client,
|
| 57 |
+
/// first checking DEBUGINFOD_CACHE_PATH.
|
| 58 |
+
Expected<std::string> getDefaultDebuginfodCacheDirectory();
|
| 59 |
+
|
| 60 |
+
/// Finds a default timeout for debuginfod HTTP requests. Checks
|
| 61 |
+
/// DEBUGINFOD_TIMEOUT environment variable, default is 90 seconds (90000 ms).
|
| 62 |
+
std::chrono::milliseconds getDefaultDebuginfodTimeout();
|
| 63 |
+
|
| 64 |
+
/// Get the full URL path for a source request of a given BuildID and file
|
| 65 |
+
/// path.
|
| 66 |
+
std::string getDebuginfodSourceUrlPath(object::BuildIDRef ID,
|
| 67 |
+
StringRef SourceFilePath);
|
| 68 |
+
|
| 69 |
+
/// Fetches a specified source file by searching the default local cache
|
| 70 |
+
/// directory and server URLs.
|
| 71 |
+
Expected<std::string> getCachedOrDownloadSource(object::BuildIDRef ID,
|
| 72 |
+
StringRef SourceFilePath);
|
| 73 |
+
|
| 74 |
+
/// Get the full URL path for an executable request of a given BuildID.
|
| 75 |
+
std::string getDebuginfodExecutableUrlPath(object::BuildIDRef ID);
|
| 76 |
+
|
| 77 |
+
/// Fetches an executable by searching the default local cache directory and
|
| 78 |
+
/// server URLs.
|
| 79 |
+
Expected<std::string> getCachedOrDownloadExecutable(object::BuildIDRef ID);
|
| 80 |
+
|
| 81 |
+
/// Get the full URL path for a debug binary request of a given BuildID.
|
| 82 |
+
std::string getDebuginfodDebuginfoUrlPath(object::BuildIDRef ID);
|
| 83 |
+
|
| 84 |
+
/// Fetches a debug binary by searching the default local cache directory and
|
| 85 |
+
/// server URLs.
|
| 86 |
+
Expected<std::string> getCachedOrDownloadDebuginfo(object::BuildIDRef ID);
|
| 87 |
+
|
| 88 |
+
/// Fetches any debuginfod artifact using the default local cache directory and
|
| 89 |
+
/// server URLs.
|
| 90 |
+
Expected<std::string> getCachedOrDownloadArtifact(StringRef UniqueKey,
|
| 91 |
+
StringRef UrlPath);
|
| 92 |
+
|
| 93 |
+
/// Fetches any debuginfod artifact using the specified local cache directory,
|
| 94 |
+
/// server URLs, and request timeout (in milliseconds). If the artifact is
|
| 95 |
+
/// found, uses the UniqueKey for the local cache file.
|
| 96 |
+
Expected<std::string> getCachedOrDownloadArtifact(
|
| 97 |
+
StringRef UniqueKey, StringRef UrlPath, StringRef CacheDirectoryPath,
|
| 98 |
+
ArrayRef<StringRef> DebuginfodUrls, std::chrono::milliseconds Timeout);
|
| 99 |
+
|
| 100 |
+
class ThreadPoolInterface;
|
| 101 |
+
|
| 102 |
+
struct DebuginfodLogEntry {
|
| 103 |
+
std::string Message;
|
| 104 |
+
DebuginfodLogEntry() = default;
|
| 105 |
+
DebuginfodLogEntry(const Twine &Message);
|
| 106 |
+
};
|
| 107 |
+
|
| 108 |
+
class DebuginfodLog {
|
| 109 |
+
std::mutex QueueMutex;
|
| 110 |
+
std::condition_variable QueueCondition;
|
| 111 |
+
std::queue<DebuginfodLogEntry> LogEntryQueue;
|
| 112 |
+
|
| 113 |
+
public:
|
| 114 |
+
// Adds a log entry to end of the queue.
|
| 115 |
+
void push(DebuginfodLogEntry Entry);
|
| 116 |
+
// Adds a log entry to end of the queue.
|
| 117 |
+
void push(const Twine &Message);
|
| 118 |
+
// Blocks until there are log entries in the queue, then pops and returns the
|
| 119 |
+
// first one.
|
| 120 |
+
DebuginfodLogEntry pop();
|
| 121 |
+
};
|
| 122 |
+
|
| 123 |
+
/// Tracks a collection of debuginfod artifacts on the local filesystem.
|
| 124 |
+
class DebuginfodCollection {
|
| 125 |
+
SmallVector<std::string, 1> Paths;
|
| 126 |
+
sys::RWMutex BinariesMutex;
|
| 127 |
+
StringMap<std::string> Binaries;
|
| 128 |
+
sys::RWMutex DebugBinariesMutex;
|
| 129 |
+
StringMap<std::string> DebugBinaries;
|
| 130 |
+
Error findBinaries(StringRef Path);
|
| 131 |
+
Expected<std::optional<std::string>> getDebugBinaryPath(object::BuildIDRef);
|
| 132 |
+
Expected<std::optional<std::string>> getBinaryPath(object::BuildIDRef);
|
| 133 |
+
// If the collection has not been updated since MinInterval, call update() and
|
| 134 |
+
// return true. Otherwise return false. If update returns an error, return the
|
| 135 |
+
// error.
|
| 136 |
+
Expected<bool> updateIfStale();
|
| 137 |
+
DebuginfodLog &Log;
|
| 138 |
+
ThreadPoolInterface &Pool;
|
| 139 |
+
Timer UpdateTimer;
|
| 140 |
+
sys::Mutex UpdateMutex;
|
| 141 |
+
|
| 142 |
+
// Minimum update interval, in seconds, for on-demand updates triggered when a
|
| 143 |
+
// build-id is not found.
|
| 144 |
+
double MinInterval;
|
| 145 |
+
|
| 146 |
+
public:
|
| 147 |
+
DebuginfodCollection(ArrayRef<StringRef> Paths, DebuginfodLog &Log,
|
| 148 |
+
ThreadPoolInterface &Pool, double MinInterval);
|
| 149 |
+
Error update();
|
| 150 |
+
Error updateForever(std::chrono::milliseconds Interval);
|
| 151 |
+
Expected<std::string> findDebugBinaryPath(object::BuildIDRef);
|
| 152 |
+
Expected<std::string> findBinaryPath(object::BuildIDRef);
|
| 153 |
+
};
|
| 154 |
+
|
| 155 |
+
struct DebuginfodServer {
|
| 156 |
+
HTTPServer Server;
|
| 157 |
+
DebuginfodLog &Log;
|
| 158 |
+
DebuginfodCollection &Collection;
|
| 159 |
+
DebuginfodServer(DebuginfodLog &Log, DebuginfodCollection &Collection);
|
| 160 |
+
};
|
| 161 |
+
|
| 162 |
+
} // end namespace llvm
|
| 163 |
+
|
| 164 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Debuginfod/HTTPClient.h
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- llvm/Support/HTTPClient.h - HTTP client library ---------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
///
|
| 9 |
+
/// \file
|
| 10 |
+
/// This file contains the declarations of the HTTPClient library for issuing
|
| 11 |
+
/// HTTP requests and handling the responses.
|
| 12 |
+
///
|
| 13 |
+
//===----------------------------------------------------------------------===//
|
| 14 |
+
|
| 15 |
+
#ifndef LLVM_DEBUGINFOD_HTTPCLIENT_H
|
| 16 |
+
#define LLVM_DEBUGINFOD_HTTPCLIENT_H
|
| 17 |
+
|
| 18 |
+
#include "llvm/ADT/SmallString.h"
|
| 19 |
+
#include "llvm/ADT/SmallVector.h"
|
| 20 |
+
#include "llvm/Support/Error.h"
|
| 21 |
+
#include "llvm/Support/MemoryBuffer.h"
|
| 22 |
+
|
| 23 |
+
#include <chrono>
|
| 24 |
+
|
| 25 |
+
namespace llvm {
|
| 26 |
+
|
| 27 |
+
enum class HTTPMethod { GET };
|
| 28 |
+
|
| 29 |
+
/// A stateless description of an outbound HTTP request.
|
| 30 |
+
struct HTTPRequest {
|
| 31 |
+
SmallString<128> Url;
|
| 32 |
+
SmallVector<std::string, 0> Headers;
|
| 33 |
+
HTTPMethod Method = HTTPMethod::GET;
|
| 34 |
+
bool FollowRedirects = true;
|
| 35 |
+
HTTPRequest(StringRef Url);
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
bool operator==(const HTTPRequest &A, const HTTPRequest &B);
|
| 39 |
+
|
| 40 |
+
/// A handler for state updates occurring while an HTTPRequest is performed.
|
| 41 |
+
/// Can trigger the client to abort the request by returning an Error from any
|
| 42 |
+
/// of its methods.
|
| 43 |
+
class HTTPResponseHandler {
|
| 44 |
+
public:
|
| 45 |
+
/// Processes an additional chunk of bytes of the HTTP response body.
|
| 46 |
+
virtual Error handleBodyChunk(StringRef BodyChunk) = 0;
|
| 47 |
+
|
| 48 |
+
protected:
|
| 49 |
+
~HTTPResponseHandler();
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
/// A reusable client that can perform HTTPRequests through a network socket.
|
| 53 |
+
class HTTPClient {
|
| 54 |
+
#ifdef LLVM_ENABLE_CURL
|
| 55 |
+
void *Curl = nullptr;
|
| 56 |
+
#endif
|
| 57 |
+
|
| 58 |
+
public:
|
| 59 |
+
HTTPClient();
|
| 60 |
+
~HTTPClient();
|
| 61 |
+
|
| 62 |
+
static bool IsInitialized;
|
| 63 |
+
|
| 64 |
+
/// Returns true only if LLVM has been compiled with a working HTTPClient.
|
| 65 |
+
static bool isAvailable();
|
| 66 |
+
|
| 67 |
+
/// Must be called at the beginning of a program, while it is a single thread.
|
| 68 |
+
static void initialize();
|
| 69 |
+
|
| 70 |
+
/// Must be called at the end of a program, while it is a single thread.
|
| 71 |
+
static void cleanup();
|
| 72 |
+
|
| 73 |
+
/// Sets the timeout for the entire request, in milliseconds. A zero or
|
| 74 |
+
/// negative value means the request never times out.
|
| 75 |
+
void setTimeout(std::chrono::milliseconds Timeout);
|
| 76 |
+
|
| 77 |
+
/// Performs the Request, passing response data to the Handler. Returns all
|
| 78 |
+
/// errors which occur during the request. Aborts if an error is returned by a
|
| 79 |
+
/// Handler method.
|
| 80 |
+
Error perform(const HTTPRequest &Request, HTTPResponseHandler &Handler);
|
| 81 |
+
|
| 82 |
+
/// Returns the last received response code or zero if none.
|
| 83 |
+
unsigned responseCode();
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
} // end namespace llvm
|
| 87 |
+
|
| 88 |
+
#endif // LLVM_DEBUGINFOD_HTTPCLIENT_H
|
deps/exla/cache/xla_extension/include/llvm/Debuginfod/HTTPServer.h
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- llvm/Debuginfod/HTTPServer.h - HTTP server library ------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
///
|
| 9 |
+
/// \file
|
| 10 |
+
/// This file contains the declarations of the HTTPServer and HTTPServerRequest
|
| 11 |
+
/// classes, the HTTPResponse, and StreamingHTTPResponse structs, and the
|
| 12 |
+
/// streamFile function.
|
| 13 |
+
///
|
| 14 |
+
//===----------------------------------------------------------------------===//
|
| 15 |
+
|
| 16 |
+
#ifndef LLVM_DEBUGINFOD_HTTPSERVER_H
|
| 17 |
+
#define LLVM_DEBUGINFOD_HTTPSERVER_H
|
| 18 |
+
|
| 19 |
+
#include "llvm/ADT/StringRef.h"
|
| 20 |
+
#include "llvm/Support/Error.h"
|
| 21 |
+
|
| 22 |
+
#ifdef LLVM_ENABLE_HTTPLIB
|
| 23 |
+
// forward declarations
|
| 24 |
+
namespace httplib {
|
| 25 |
+
class Request;
|
| 26 |
+
class Response;
|
| 27 |
+
class Server;
|
| 28 |
+
} // namespace httplib
|
| 29 |
+
#endif
|
| 30 |
+
|
| 31 |
+
namespace llvm {
|
| 32 |
+
|
| 33 |
+
struct HTTPResponse;
|
| 34 |
+
struct StreamingHTTPResponse;
|
| 35 |
+
class HTTPServer;
|
| 36 |
+
|
| 37 |
+
class HTTPServerError : public ErrorInfo<HTTPServerError, ECError> {
|
| 38 |
+
public:
|
| 39 |
+
static char ID;
|
| 40 |
+
HTTPServerError(const Twine &Msg);
|
| 41 |
+
void log(raw_ostream &OS) const override;
|
| 42 |
+
|
| 43 |
+
private:
|
| 44 |
+
std::string Msg;
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
class HTTPServerRequest {
|
| 48 |
+
friend HTTPServer;
|
| 49 |
+
|
| 50 |
+
#ifdef LLVM_ENABLE_HTTPLIB
|
| 51 |
+
private:
|
| 52 |
+
HTTPServerRequest(const httplib::Request &HTTPLibRequest,
|
| 53 |
+
httplib::Response &HTTPLibResponse);
|
| 54 |
+
httplib::Response &HTTPLibResponse;
|
| 55 |
+
#endif
|
| 56 |
+
|
| 57 |
+
public:
|
| 58 |
+
std::string UrlPath;
|
| 59 |
+
/// The elements correspond to match groups in the url path matching regex.
|
| 60 |
+
SmallVector<std::string, 1> UrlPathMatches;
|
| 61 |
+
|
| 62 |
+
// TODO bring in HTTP headers
|
| 63 |
+
|
| 64 |
+
void setResponse(StreamingHTTPResponse Response);
|
| 65 |
+
void setResponse(HTTPResponse Response);
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
struct HTTPResponse {
|
| 69 |
+
unsigned Code;
|
| 70 |
+
const char *ContentType;
|
| 71 |
+
StringRef Body;
|
| 72 |
+
};
|
| 73 |
+
|
| 74 |
+
typedef std::function<void(HTTPServerRequest &)> HTTPRequestHandler;
|
| 75 |
+
|
| 76 |
+
/// An HTTPContentProvider is called by the HTTPServer to obtain chunks of the
|
| 77 |
+
/// streaming response body. The returned chunk should be located at Offset
|
| 78 |
+
/// bytes and have Length bytes.
|
| 79 |
+
typedef std::function<StringRef(size_t /*Offset*/, size_t /*Length*/)>
|
| 80 |
+
HTTPContentProvider;
|
| 81 |
+
|
| 82 |
+
/// Wraps the content provider with HTTP Status code and headers.
|
| 83 |
+
struct StreamingHTTPResponse {
|
| 84 |
+
unsigned Code;
|
| 85 |
+
const char *ContentType;
|
| 86 |
+
size_t ContentLength;
|
| 87 |
+
HTTPContentProvider Provider;
|
| 88 |
+
/// Called after the response transfer is complete with the success value of
|
| 89 |
+
/// the transfer.
|
| 90 |
+
std::function<void(bool)> CompletionHandler = [](bool Success) {};
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
/// Sets the response to stream the file at FilePath, if available, and
|
| 94 |
+
/// otherwise an HTTP 404 error response.
|
| 95 |
+
bool streamFile(HTTPServerRequest &Request, StringRef FilePath);
|
| 96 |
+
|
| 97 |
+
/// An HTTP server which can listen on a single TCP/IP port for HTTP
|
| 98 |
+
/// requests and delgate them to the appropriate registered handler.
|
| 99 |
+
class HTTPServer {
|
| 100 |
+
#ifdef LLVM_ENABLE_HTTPLIB
|
| 101 |
+
std::unique_ptr<httplib::Server> Server;
|
| 102 |
+
unsigned Port = 0;
|
| 103 |
+
#endif
|
| 104 |
+
public:
|
| 105 |
+
HTTPServer();
|
| 106 |
+
~HTTPServer();
|
| 107 |
+
|
| 108 |
+
/// Returns true only if LLVM has been compiled with a working HTTPServer.
|
| 109 |
+
static bool isAvailable();
|
| 110 |
+
|
| 111 |
+
/// Registers a URL pattern routing rule. When the server is listening, each
|
| 112 |
+
/// request is dispatched to the first registered handler whose UrlPathPattern
|
| 113 |
+
/// matches the UrlPath.
|
| 114 |
+
Error get(StringRef UrlPathPattern, HTTPRequestHandler Handler);
|
| 115 |
+
|
| 116 |
+
/// Attempts to assign the requested port and interface, returning an Error
|
| 117 |
+
/// upon failure.
|
| 118 |
+
Error bind(unsigned Port, const char *HostInterface = "0.0.0.0");
|
| 119 |
+
|
| 120 |
+
/// Attempts to assign any available port and interface, returning either the
|
| 121 |
+
/// port number or an Error upon failure.
|
| 122 |
+
Expected<unsigned> bind(const char *HostInterface = "0.0.0.0");
|
| 123 |
+
|
| 124 |
+
/// Attempts to listen for requests on the bound port. Returns an Error if
|
| 125 |
+
/// called before binding a port.
|
| 126 |
+
Error listen();
|
| 127 |
+
|
| 128 |
+
/// If the server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|
|
|
|
|
|
| 1 |
+
//===--- Demangle.h ---------------------------------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
|
| 9 |
+
#ifndef LLVM_DEMANGLE_DEMANGLE_H
|
| 10 |
+
#define LLVM_DEMANGLE_DEMANGLE_H
|
| 11 |
+
|
| 12 |
+
#include <cstddef>
|
| 13 |
+
#include <optional>
|
| 14 |
+
#include <string>
|
| 15 |
+
#include <string_view>
|
| 16 |
+
|
| 17 |
+
namespace llvm {
|
| 18 |
+
/// This is a llvm local version of __cxa_demangle. Other than the name and
|
| 19 |
+
/// being in the llvm namespace it is identical.
|
| 20 |
+
///
|
| 21 |
+
/// The mangled_name is demangled into buf and returned. If the buffer is not
|
| 22 |
+
/// large enough, realloc is used to expand it.
|
| 23 |
+
///
|
| 24 |
+
/// The *status will be set to a value from the following enumeration
|
| 25 |
+
enum : int {
|
| 26 |
+
demangle_unknown_error = -4,
|
| 27 |
+
demangle_invalid_args = -3,
|
| 28 |
+
demangle_invalid_mangled_name = -2,
|
| 29 |
+
demangle_memory_alloc_failure = -1,
|
| 30 |
+
demangle_success = 0,
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
/// Returns a non-NULL pointer to a NUL-terminated C style string
|
| 34 |
+
/// that should be explicitly freed, if successful. Otherwise, may return
|
| 35 |
+
/// nullptr if mangled_name is not a valid mangling or is nullptr.
|
| 36 |
+
char *itaniumDemangle(std::string_view mangled_name, bool ParseParams = true);
|
| 37 |
+
|
| 38 |
+
enum MSDemangleFlags {
|
| 39 |
+
MSDF_None = 0,
|
| 40 |
+
MSDF_DumpBackrefs = 1 << 0,
|
| 41 |
+
MSDF_NoAccessSpecifier = 1 << 1,
|
| 42 |
+
MSDF_NoCallingConvention = 1 << 2,
|
| 43 |
+
MSDF_NoReturnType = 1 << 3,
|
| 44 |
+
MSDF_NoMemberType = 1 << 4,
|
| 45 |
+
MSDF_NoVariableType = 1 << 5,
|
| 46 |
+
};
|
| 47 |
+
|
| 48 |
+
/// Demangles the Microsoft symbol pointed at by mangled_name and returns it.
|
| 49 |
+
/// Returns a pointer to the start of a null-terminated demangled string on
|
| 50 |
+
/// success, or nullptr on error.
|
| 51 |
+
/// If n_read is non-null and demangling was successful, it receives how many
|
| 52 |
+
/// bytes of the input string were consumed.
|
| 53 |
+
/// status receives one of the demangle_ enum entries above if it's not nullptr.
|
| 54 |
+
/// Flags controls various details of the demangled representation.
|
| 55 |
+
char *microsoftDemangle(std::string_view mangled_name, size_t *n_read,
|
| 56 |
+
int *status, MSDemangleFlags Flags = MSDF_None);
|
| 57 |
+
|
| 58 |
+
std::optional<size_t>
|
| 59 |
+
getArm64ECInsertionPointInMangledName(std::string_view MangledName);
|
| 60 |
+
|
| 61 |
+
// Demangles a Rust v0 mangled symbol.
|
| 62 |
+
char *rustDemangle(std::string_view MangledName);
|
| 63 |
+
|
| 64 |
+
// Demangles a D mangled symbol.
|
| 65 |
+
char *dlangDemangle(std::string_view MangledName);
|
| 66 |
+
|
| 67 |
+
/// Attempt to demangle a string using different demangling schemes.
|
| 68 |
+
/// The function uses heuristics to determine which demangling scheme to use.
|
| 69 |
+
/// \param MangledName - reference to string to demangle.
|
| 70 |
+
/// \returns - the demangled string, or a copy of the input string if no
|
| 71 |
+
/// demangling occurred.
|
| 72 |
+
std::string demangle(std::string_view MangledName);
|
| 73 |
+
|
| 74 |
+
bool nonMicrosoftDemangle(std::string_view MangledName, std::string &Result,
|
| 75 |
+
bool CanHaveLeadingDot = true,
|
| 76 |
+
bool ParseParams = true);
|
| 77 |
+
|
| 78 |
+
/// "Partial" demangler. This supports demangling a string into an AST
|
| 79 |
+
/// (typically an intermediate stage in itaniumDemangle) and querying certain
|
| 80 |
+
/// properties or partially printing the demangled name.
|
| 81 |
+
struct ItaniumPartialDemangler {
|
| 82 |
+
ItaniumPartialDemangler();
|
| 83 |
+
|
| 84 |
+
ItaniumPartialDemangler(ItaniumPartialDemangler &&Other);
|
| 85 |
+
ItaniumPartialDemangler &operator=(ItaniumPartialDemangler &&Other);
|
| 86 |
+
|
| 87 |
+
/// Demangle into an AST. Subsequent calls to the rest of the member functions
|
| 88 |
+
/// implicitly operate on the AST this produces.
|
| 89 |
+
/// \return true on error, false otherwise
|
| 90 |
+
bool partialDemangle(const char *MangledName);
|
| 91 |
+
|
| 92 |
+
/// Just print the entire mangled name into Buf. Buf and N behave like the
|
| 93 |
+
/// second and third parameters to __cxa_demangle.
|
| 94 |
+
char *finishDemangle(char *Buf, size_t *N) const;
|
| 95 |
+
|
| 96 |
+
/// See \ref finishDemangle
|
| 97 |
+
///
|
| 98 |
+
/// \param[in] OB A llvm::itanium_demangle::OutputBuffer that the demangled
|
| 99 |
+
/// name will be printed into.
|
| 100 |
+
///
|
| 101 |
+
char *finishDemangle(void *OB) const;
|
| 102 |
+
|
| 103 |
+
/// Get the base name of a function. This doesn't include trailing template
|
| 104 |
+
/// arguments, ie for "a::b<int>" this function returns "b".
|
| 105 |
+
char *getFunctionBaseName(char *Buf, size_t *N) const;
|
| 106 |
+
|
| 107 |
+
/// Get the context name for a function. For "a::b::c", this function returns
|
| 108 |
+
/// "a::b".
|
| 109 |
+
char *getFunctionDeclContextName(char *Buf, size_t *N) const;
|
| 110 |
+
|
| 111 |
+
/// Get the entire name of this function.
|
| 112 |
+
char *getFunctionName(char *Buf, size_t *N) const;
|
| 113 |
+
|
| 114 |
+
/// Get the parameters for this function.
|
| 115 |
+
char *getFunctionParameters(char *Buf, size_t *N) const;
|
| 116 |
+
char *getFunctionReturnType(char *Buf, size_t *N) const;
|
| 117 |
+
|
| 118 |
+
/// If this function has any cv or reference qualifiers. These imply that
|
| 119 |
+
/// the function is a non-static member function.
|
| 120 |
+
bool hasFunctionQualifiers() const;
|
| 121 |
+
|
| 122 |
+
/// If this symbol describes a constructor or destructor.
|
| 123 |
+
bool isCtorOrDtor() const;
|
| 124 |
+
|
| 125 |
+
/// If this symbol describes a function.
|
| 126 |
+
bool isFunction() const;
|
| 127 |
+
|
| 128 |
+
/// If this symbol describes a variable.
|
| 129 |
+
bool isData() const;
|
| 130 |
+
|
| 131 |
+
/// If this symbol is a <special-name>. These are generally implicitly
|
| 132 |
+
/// generated by the implementation, such as vtables and typeinfo names.
|
| 133 |
+
bool isSpecialName() const;
|
| 134 |
+
|
| 135 |
+
~ItaniumPartialDemangler();
|
| 136 |
+
|
| 137 |
+
private:
|
| 138 |
+
void *RootNode;
|
| 139 |
+
void *Context;
|
| 140 |
+
};
|
| 141 |
+
} // namespace llvm
|
| 142 |
+
|
| 143 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Demangle/DemangleConfig.h
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===--- DemangleConfig.h ---------------------------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file contains a variety of feature test macros copied from
|
| 10 |
+
// include/llvm/Support/Compiler.h so that LLVMDemangle does not need to take
|
| 11 |
+
// a dependency on LLVMSupport.
|
| 12 |
+
//
|
| 13 |
+
//===----------------------------------------------------------------------===//
|
| 14 |
+
|
| 15 |
+
#ifndef LLVM_DEMANGLE_DEMANGLECONFIG_H
|
| 16 |
+
#define LLVM_DEMANGLE_DEMANGLECONFIG_H
|
| 17 |
+
|
| 18 |
+
#ifndef __has_feature
|
| 19 |
+
#define __has_feature(x) 0
|
| 20 |
+
#endif
|
| 21 |
+
|
| 22 |
+
#ifndef __has_cpp_attribute
|
| 23 |
+
#define __has_cpp_attribute(x) 0
|
| 24 |
+
#endif
|
| 25 |
+
|
| 26 |
+
#ifndef __has_attribute
|
| 27 |
+
#define __has_attribute(x) 0
|
| 28 |
+
#endif
|
| 29 |
+
|
| 30 |
+
#ifndef __has_builtin
|
| 31 |
+
#define __has_builtin(x) 0
|
| 32 |
+
#endif
|
| 33 |
+
|
| 34 |
+
#ifndef DEMANGLE_GNUC_PREREQ
|
| 35 |
+
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
|
| 36 |
+
#define DEMANGLE_GNUC_PREREQ(maj, min, patch) \
|
| 37 |
+
((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
|
| 38 |
+
((maj) << 20) + ((min) << 10) + (patch))
|
| 39 |
+
#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
|
| 40 |
+
#define DEMANGLE_GNUC_PREREQ(maj, min, patch) \
|
| 41 |
+
((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
|
| 42 |
+
#else
|
| 43 |
+
#define DEMANGLE_GNUC_PREREQ(maj, min, patch) 0
|
| 44 |
+
#endif
|
| 45 |
+
#endif
|
| 46 |
+
|
| 47 |
+
#if __has_attribute(used) || DEMANGLE_GNUC_PREREQ(3, 1, 0)
|
| 48 |
+
#define DEMANGLE_ATTRIBUTE_USED __attribute__((__used__))
|
| 49 |
+
#else
|
| 50 |
+
#define DEMANGLE_ATTRIBUTE_USED
|
| 51 |
+
#endif
|
| 52 |
+
|
| 53 |
+
#if __has_builtin(__builtin_unreachable) || DEMANGLE_GNUC_PREREQ(4, 5, 0)
|
| 54 |
+
#define DEMANGLE_UNREACHABLE __builtin_unreachable()
|
| 55 |
+
#elif defined(_MSC_VER)
|
| 56 |
+
#define DEMANGLE_UNREACHABLE __assume(false)
|
| 57 |
+
#else
|
| 58 |
+
#define DEMANGLE_UNREACHABLE
|
| 59 |
+
#endif
|
| 60 |
+
|
| 61 |
+
#if __has_attribute(noinline) || DEMANGLE_GNUC_PREREQ(3, 4, 0)
|
| 62 |
+
#define DEMANGLE_ATTRIBUTE_NOINLINE __attribute__((noinline))
|
| 63 |
+
#elif defined(_MSC_VER)
|
| 64 |
+
#define DEMANGLE_ATTRIBUTE_NOINLINE __declspec(noinline)
|
| 65 |
+
#else
|
| 66 |
+
#define DEMANGLE_ATTRIBUTE_NOINLINE
|
| 67 |
+
#endif
|
| 68 |
+
|
| 69 |
+
#if !defined(NDEBUG)
|
| 70 |
+
#define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE DEMANGLE_ATTRIBUTE_USED
|
| 71 |
+
#else
|
| 72 |
+
#define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE
|
| 73 |
+
#endif
|
| 74 |
+
|
| 75 |
+
#if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
|
| 76 |
+
#define DEMANGLE_FALLTHROUGH [[fallthrough]]
|
| 77 |
+
#elif __has_cpp_attribute(gnu::fallthrough)
|
| 78 |
+
#define DEMANGLE_FALLTHROUGH [[gnu::fallthrough]]
|
| 79 |
+
#elif !__cplusplus
|
| 80 |
+
// Workaround for llvm.org/PR23435, since clang 3.6 and below emit a spurious
|
| 81 |
+
// error when __has_cpp_attribute is given a scoped attribute in C mode.
|
| 82 |
+
#define DEMANGLE_FALLTHROUGH
|
| 83 |
+
#elif __has_cpp_attribute(clang::fallthrough)
|
| 84 |
+
#define DEMANGLE_FALLTHROUGH [[clang::fallthrough]]
|
| 85 |
+
#else
|
| 86 |
+
#define DEMANGLE_FALLTHROUGH
|
| 87 |
+
#endif
|
| 88 |
+
|
| 89 |
+
#ifndef DEMANGLE_ASSERT
|
| 90 |
+
#include <cassert>
|
| 91 |
+
#define DEMANGLE_ASSERT(__expr, __msg) assert((__expr) && (__msg))
|
| 92 |
+
#endif
|
| 93 |
+
|
| 94 |
+
#define DEMANGLE_NAMESPACE_BEGIN namespace llvm { namespace itanium_demangle {
|
| 95 |
+
#define DEMANGLE_NAMESPACE_END } }
|
| 96 |
+
|
| 97 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Demangle/ItaniumDemangle.h
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
deps/exla/cache/xla_extension/include/llvm/Demangle/ItaniumNodes.def
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===--- ItaniumNodes.def ------------*- mode:c++;eval:(read-only-mode) -*-===//
|
| 2 |
+
// Do not edit! See README.txt.
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// Define the demangler's node names
|
| 10 |
+
|
| 11 |
+
#ifndef NODE
|
| 12 |
+
#error Define NODE to handle nodes
|
| 13 |
+
#endif
|
| 14 |
+
|
| 15 |
+
NODE(NodeArrayNode)
|
| 16 |
+
NODE(DotSuffix)
|
| 17 |
+
NODE(VendorExtQualType)
|
| 18 |
+
NODE(QualType)
|
| 19 |
+
NODE(ConversionOperatorType)
|
| 20 |
+
NODE(PostfixQualifiedType)
|
| 21 |
+
NODE(ElaboratedTypeSpefType)
|
| 22 |
+
NODE(TransformedType)
|
| 23 |
+
NODE(NameType)
|
| 24 |
+
NODE(AbiTagAttr)
|
| 25 |
+
NODE(EnableIfAttr)
|
| 26 |
+
NODE(ObjCProtoName)
|
| 27 |
+
NODE(PointerType)
|
| 28 |
+
NODE(ReferenceType)
|
| 29 |
+
NODE(PointerToMemberType)
|
| 30 |
+
NODE(ArrayType)
|
| 31 |
+
NODE(FunctionType)
|
| 32 |
+
NODE(NoexceptSpec)
|
| 33 |
+
NODE(DynamicExceptionSpec)
|
| 34 |
+
NODE(FunctionEncoding)
|
| 35 |
+
NODE(LiteralOperator)
|
| 36 |
+
NODE(SpecialName)
|
| 37 |
+
NODE(CtorVtableSpecialName)
|
| 38 |
+
NODE(QualifiedName)
|
| 39 |
+
NODE(NestedName)
|
| 40 |
+
NODE(MemberLikeFriendName)
|
| 41 |
+
NODE(LocalName)
|
| 42 |
+
NODE(ModuleName)
|
| 43 |
+
NODE(ModuleEntity)
|
| 44 |
+
NODE(VectorType)
|
| 45 |
+
NODE(PixelVectorType)
|
| 46 |
+
NODE(BinaryFPType)
|
| 47 |
+
NODE(BitIntType)
|
| 48 |
+
NODE(SyntheticTemplateParamName)
|
| 49 |
+
NODE(TemplateParamQualifiedArg)
|
| 50 |
+
NODE(TypeTemplateParamDecl)
|
| 51 |
+
NODE(ConstrainedTypeTemplateParamDecl)
|
| 52 |
+
NODE(NonTypeTemplateParamDecl)
|
| 53 |
+
NODE(TemplateTemplateParamDecl)
|
| 54 |
+
NODE(TemplateParamPackDecl)
|
| 55 |
+
NODE(ParameterPack)
|
| 56 |
+
NODE(TemplateArgumentPack)
|
| 57 |
+
NODE(ParameterPackExpansion)
|
| 58 |
+
NODE(TemplateArgs)
|
| 59 |
+
NODE(ForwardTemplateReference)
|
| 60 |
+
NODE(NameWithTemplateArgs)
|
| 61 |
+
NODE(GlobalQualifiedName)
|
| 62 |
+
NODE(ExpandedSpecialSubstitution)
|
| 63 |
+
NODE(SpecialSubstitution)
|
| 64 |
+
NODE(CtorDtorName)
|
| 65 |
+
NODE(DtorName)
|
| 66 |
+
NODE(UnnamedTypeName)
|
| 67 |
+
NODE(ClosureTypeName)
|
| 68 |
+
NODE(StructuredBindingName)
|
| 69 |
+
NODE(BinaryExpr)
|
| 70 |
+
NODE(ArraySubscriptExpr)
|
| 71 |
+
NODE(PostfixExpr)
|
| 72 |
+
NODE(ConditionalExpr)
|
| 73 |
+
NODE(MemberExpr)
|
| 74 |
+
NODE(SubobjectExpr)
|
| 75 |
+
NODE(EnclosingExpr)
|
| 76 |
+
NODE(CastExpr)
|
| 77 |
+
NODE(SizeofParamPackExpr)
|
| 78 |
+
NODE(CallExpr)
|
| 79 |
+
NODE(NewExpr)
|
| 80 |
+
NODE(DeleteExpr)
|
| 81 |
+
NODE(PrefixExpr)
|
| 82 |
+
NODE(FunctionParam)
|
| 83 |
+
NODE(ConversionExpr)
|
| 84 |
+
NODE(PointerToMemberConversionExpr)
|
| 85 |
+
NODE(InitListExpr)
|
| 86 |
+
NODE(FoldExpr)
|
| 87 |
+
NODE(ThrowExpr)
|
| 88 |
+
NODE(BoolExpr)
|
| 89 |
+
NODE(StringLiteral)
|
| 90 |
+
NODE(LambdaExpr)
|
| 91 |
+
NODE(EnumLiteral)
|
| 92 |
+
NODE(IntegerLiteral)
|
| 93 |
+
NODE(FloatLiteral)
|
| 94 |
+
NODE(DoubleLiteral)
|
| 95 |
+
NODE(LongDoubleLiteral)
|
| 96 |
+
NODE(BracedExpr)
|
| 97 |
+
NODE(BracedRangeExpr)
|
| 98 |
+
NODE(RequiresExpr)
|
| 99 |
+
NODE(ExprRequirement)
|
| 100 |
+
NODE(TypeRequirement)
|
| 101 |
+
NODE(NestedRequirement)
|
| 102 |
+
NODE(ExplicitObjectParameter)
|
| 103 |
+
|
| 104 |
+
#undef NODE
|
deps/exla/cache/xla_extension/include/llvm/Demangle/MicrosoftDemangle.h
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===------------------------- MicrosoftDemangle.h --------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
|
| 9 |
+
#ifndef LLVM_DEMANGLE_MICROSOFTDEMANGLE_H
|
| 10 |
+
#define LLVM_DEMANGLE_MICROSOFTDEMANGLE_H
|
| 11 |
+
|
| 12 |
+
#include "llvm/Demangle/Demangle.h"
|
| 13 |
+
#include "llvm/Demangle/MicrosoftDemangleNodes.h"
|
| 14 |
+
|
| 15 |
+
#include <cassert>
|
| 16 |
+
#include <string_view>
|
| 17 |
+
#include <utility>
|
| 18 |
+
|
| 19 |
+
namespace llvm {
|
| 20 |
+
namespace ms_demangle {
|
| 21 |
+
// This memory allocator is extremely fast, but it doesn't call dtors
|
| 22 |
+
// for allocated objects. That means you can't use STL containers
|
| 23 |
+
// (such as std::vector) with this allocator. But it pays off --
|
| 24 |
+
// the demangler is 3x faster with this allocator compared to one with
|
| 25 |
+
// STL containers.
|
| 26 |
+
constexpr size_t AllocUnit = 4096;
|
| 27 |
+
|
| 28 |
+
class ArenaAllocator {
|
| 29 |
+
struct AllocatorNode {
|
| 30 |
+
uint8_t *Buf = nullptr;
|
| 31 |
+
size_t Used = 0;
|
| 32 |
+
size_t Capacity = 0;
|
| 33 |
+
AllocatorNode *Next = nullptr;
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
void addNode(size_t Capacity) {
|
| 37 |
+
AllocatorNode *NewHead = new AllocatorNode;
|
| 38 |
+
NewHead->Buf = new uint8_t[Capacity];
|
| 39 |
+
NewHead->Next = Head;
|
| 40 |
+
NewHead->Capacity = Capacity;
|
| 41 |
+
Head = NewHead;
|
| 42 |
+
NewHead->Used = 0;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
public:
|
| 46 |
+
ArenaAllocator() { addNode(AllocUnit); }
|
| 47 |
+
|
| 48 |
+
~ArenaAllocator() {
|
| 49 |
+
while (Head) {
|
| 50 |
+
assert(Head->Buf);
|
| 51 |
+
delete[] Head->Buf;
|
| 52 |
+
AllocatorNode *Next = Head->Next;
|
| 53 |
+
delete Head;
|
| 54 |
+
Head = Next;
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
// Delete the copy constructor and the copy assignment operator.
|
| 59 |
+
ArenaAllocator(const ArenaAllocator &) = delete;
|
| 60 |
+
ArenaAllocator &operator=(const ArenaAllocator &) = delete;
|
| 61 |
+
|
| 62 |
+
char *allocUnalignedBuffer(size_t Size) {
|
| 63 |
+
assert(Head && Head->Buf);
|
| 64 |
+
|
| 65 |
+
uint8_t *P = Head->Buf + Head->Used;
|
| 66 |
+
|
| 67 |
+
Head->Used += Size;
|
| 68 |
+
if (Head->Used <= Head->Capacity)
|
| 69 |
+
return reinterpret_cast<char *>(P);
|
| 70 |
+
|
| 71 |
+
addNode(std::max(AllocUnit, Size));
|
| 72 |
+
Head->Used = Size;
|
| 73 |
+
return reinterpret_cast<char *>(Head->Buf);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
template <typename T, typename... Args> T *allocArray(size_t Count) {
|
| 77 |
+
size_t Size = Count * sizeof(T);
|
| 78 |
+
assert(Head && Head->Buf);
|
| 79 |
+
|
| 80 |
+
size_t P = (size_t)Head->Buf + Head->Used;
|
| 81 |
+
uintptr_t AlignedP =
|
| 82 |
+
(((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
|
| 83 |
+
uint8_t *PP = (uint8_t *)AlignedP;
|
| 84 |
+
size_t Adjustment = AlignedP - P;
|
| 85 |
+
|
| 86 |
+
Head->Used += Size + Adjustment;
|
| 87 |
+
if (Head->Used <= Head->Capacity)
|
| 88 |
+
return new (PP) T[Count]();
|
| 89 |
+
|
| 90 |
+
addNode(std::max(AllocUnit, Size));
|
| 91 |
+
Head->Used = Size;
|
| 92 |
+
return new (Head->Buf) T[Count]();
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
|
| 96 |
+
constexpr size_t Size = sizeof(T);
|
| 97 |
+
assert(Head && Head->Buf);
|
| 98 |
+
|
| 99 |
+
size_t P = (size_t)Head->Buf + Head->Used;
|
| 100 |
+
uintptr_t AlignedP =
|
| 101 |
+
(((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
|
| 102 |
+
uint8_t *PP = (uint8_t *)AlignedP;
|
| 103 |
+
size_t Adjustment = AlignedP - P;
|
| 104 |
+
|
| 105 |
+
Head->Used += Size + Adjustment;
|
| 106 |
+
if (Head->Used <= Head->Capacity)
|
| 107 |
+
return new (PP) T(std::forward<Args>(ConstructorArgs)...);
|
| 108 |
+
|
| 109 |
+
static_assert(Size < AllocUnit);
|
| 110 |
+
addNode(AllocUnit);
|
| 111 |
+
Head->Used = Size;
|
| 112 |
+
return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
private:
|
| 116 |
+
AllocatorNode *Head = nullptr;
|
| 117 |
+
};
|
| 118 |
+
|
| 119 |
+
struct BackrefContext {
|
| 120 |
+
static constexpr size_t Max = 10;
|
| 121 |
+
|
| 122 |
+
TypeNode *FunctionParams[Max];
|
| 123 |
+
size_t FunctionParamCount = 0;
|
| 124 |
+
|
| 125 |
+
// The first 10 BackReferences in a mangled name can be back-referenced by
|
| 126 |
+
// special name @[0-9]. This is a storage for the first 10 BackReferences.
|
| 127 |
+
NamedIdentifierNode *Names[Max];
|
| 128 |
+
size_t NamesCount = 0;
|
| 129 |
+
};
|
| 130 |
+
|
| 131 |
+
enum class QualifierMangleMode { Drop, Mangle, Result };
|
| 132 |
+
|
| 133 |
+
enum NameBackrefBehavior : uint8_t {
|
| 134 |
+
NBB_None = 0, // don't save any names as backrefs.
|
| 135 |
+
NBB_Template = 1 << 0, // save template instanations.
|
| 136 |
+
NBB_Simple = 1 << 1, // save simple names.
|
| 137 |
+
};
|
| 138 |
+
|
| 139 |
+
enum class FunctionIdentifierCodeGroup { Basic, Under, DoubleUnder };
|
| 140 |
+
|
| 141 |
+
// Demangler class takes the main role in demangling symbols.
|
| 142 |
+
// It has a set of functions to parse mangled symbols into Type instances.
|
| 143 |
+
// It also has a set of functions to convert Type instances to strings.
|
| 144 |
+
class Demangler {
|
| 145 |
+
friend std::optional<size_t>
|
| 146 |
+
llvm::getArm64ECInsertionPointInMangledName(std::string_view MangledName);
|
| 147 |
+
|
| 148 |
+
public:
|
| 149 |
+
Demangler() = default;
|
| 150 |
+
virtual ~Demangler() = default;
|
| 151 |
+
|
| 152 |
+
// You are supposed to call parse() first and then check if error is true. If
|
| 153 |
+
// it is false, call output() to write the formatted name to the given stream.
|
| 154 |
+
SymbolNode *parse(std::string_view &MangledName);
|
| 155 |
+
|
| 156 |
+
TagTypeNode *parseTagUniqueName(std::string_view &MangledName);
|
| 157 |
+
|
| 158 |
+
// True if an error occurred.
|
| 159 |
+
bool Error = false;
|
| 160 |
+
|
| 161 |
+
void dumpBackReferences();
|
| 162 |
+
|
| 163 |
+
private:
|
| 164 |
+
SymbolNode *demangleEncodedSymbol(std::string_view &MangledName,
|
| 165 |
+
QualifiedNameNode *QN);
|
| 166 |
+
SymbolNode *demangleDeclarator(std::string_view &MangledName);
|
| 167 |
+
SymbolNode *demangleMD5Name(std::string_view &MangledName);
|
| 168 |
+
SymbolNode *demangleTypeinfoName(std::string_view &MangledName);
|
| 169 |
+
|
| 170 |
+
VariableSymbolNode *demangleVariableEncoding(std::string_view &MangledName,
|
| 171 |
+
StorageClass SC);
|
| 172 |
+
FunctionSymbolNode *demangleFunctionEncoding(std::string_view &MangledName);
|
| 173 |
+
|
| 174 |
+
Qualifiers demanglePointerExtQualifiers(std::string_view &MangledName);
|
| 175 |
+
|
| 176 |
+
bool isMemberPointer(std::string_view MangledName, bool &Error);
|
| 177 |
+
|
| 178 |
+
std::optional<PointerAuthQualifierNode::ArgArray>
|
| 179 |
+
demanglePointerAuthQualifier(std::string_view &MangledName);
|
| 180 |
+
|
| 181 |
+
PointerAuthQualifierNode *
|
| 182 |
+
createPointerAuthQualifier(std::string_view &MangledName);
|
| 183 |
+
|
| 184 |
+
// Parser functions. This is a recursive-descent parser.
|
| 185 |
+
TypeNode *demangleType(std::string_view &MangledName,
|
| 186 |
+
QualifierMangleMode QMM);
|
| 187 |
+
PrimitiveTypeNode *demanglePrimitiveType(std::string_view &MangledName);
|
| 188 |
+
CustomTypeNode *demangleCustomType(std::string_view &MangledName);
|
| 189 |
+
TagTypeNode *demangleClassType(std::string_view &MangledName);
|
| 190 |
+
PointerTypeNode *demanglePointerType(std::string_view &MangledName);
|
| 191 |
+
PointerTypeNode *demangleMemberPointerType(std::string_view &MangledName);
|
| 192 |
+
FunctionSignatureNode *demangleFunctionType(std::string_view &MangledName,
|
| 193 |
+
bool HasThisQuals);
|
| 194 |
+
|
| 195 |
+
ArrayTypeNode *demangleArrayType(std::string_view &MangledName);
|
| 196 |
+
|
| 197 |
+
NodeArrayNode *demangleFunctionParameterList(std::string_view &MangledName,
|
| 198 |
+
bool &IsVariadic);
|
| 199 |
+
NodeArrayNode *demangleTemplateParameterList(std::string_view &MangledName);
|
| 200 |
+
|
| 201 |
+
std::pair<uint64_t, bool> demangleNumber(std::string_view &MangledName);
|
| 202 |
+
uint64_t demangleUnsigned(std::string_view &MangledName);
|
| 203 |
+
int64_t demangleSigned(std::string_view &MangledName);
|
| 204 |
+
|
| 205 |
+
void memorizeString(std::string_view s);
|
| 206 |
+
void memorizeIdentifier(IdentifierNode *Identifier);
|
| 207 |
+
|
| 208 |
+
/// Allocate a copy of \p Borrowed into memory that we own.
|
| 209 |
+
std::string_view copyString(std::string_view Borrowed);
|
| 210 |
+
|
| 211 |
+
QualifiedNameNode *
|
| 212 |
+
demangleFullyQualifiedTypeName(std::string_view &MangledName);
|
| 213 |
+
QualifiedNameNode *
|
| 214 |
+
demangleFullyQualifiedSymbolName(std::string_view &MangledName);
|
| 215 |
+
|
| 216 |
+
IdentifierNode *demangleUnqualifiedTypeName(std::string_view &MangledName,
|
| 217 |
+
bool Memorize);
|
| 218 |
+
IdentifierNode *demangleUnqualifiedSymbolName(std::string_view &MangledName,
|
| 219 |
+
NameBackrefBehavior NBB);
|
| 220 |
+
|
| 221 |
+
QualifiedNameNode *demangleNameScopeChain(std::string_view &MangledName,
|
| 222 |
+
IdentifierNode *UnqualifiedName);
|
| 223 |
+
IdentifierNode *demangleNameScopePiece(std::string_view &MangledName);
|
| 224 |
+
|
| 225 |
+
NamedIdentifierNode *demangleBackRefName(std::string_view &MangledName);
|
| 226 |
+
IdentifierNode *
|
| 227 |
+
demangleTemplateInstantiationName(std::string_view &MangledName,
|
| 228 |
+
NameBackrefBehavior NBB);
|
| 229 |
+
IntrinsicFunctionKind
|
| 230 |
+
translateIntrinsicFunctionCode(char CH, FunctionIdentifierCodeGroup Group);
|
| 231 |
+
IdentifierNode *demangleFunctionIdentifierCode(std::string_view &MangledName);
|
| 232 |
+
IdentifierNode *
|
| 233 |
+
demangleFunctionIdentifierCode(std::string_view &MangledName,
|
| 234 |
+
FunctionIdentifierCodeGroup Group);
|
| 235 |
+
StructorIdentifierNode *
|
| 236 |
+
demangleStructorIdentifier(std::string_view &MangledName, bool IsDestructor);
|
| 237 |
+
ConversionOperatorIdentifierNode *
|
| 238 |
+
demangleConversionOperatorIdentifier(std::string_view &MangledName);
|
| 239 |
+
LiteralOperatorIdentifierNode *
|
| 240 |
+
demangleLiteralOperatorIdentifier(std::string_view &MangledName);
|
| 241 |
+
|
| 242 |
+
SymbolNode *demangleSpecialIntrinsic(std::string_view &MangledName);
|
| 243 |
+
SpecialTableSymbolNode *
|
| 244 |
+
demangleSpecialTableSymbolNode(std::string_view &MangledName,
|
| 245 |
+
SpecialIntrinsicKind SIK);
|
| 246 |
+
LocalStaticGuardVariableNode *
|
| 247 |
+
demangleLocalStaticGuard(std::string_view &MangledName, bool IsThread);
|
| 248 |
+
VariableSymbolNode *demangleUntypedVariable(ArenaAllocator &Arena,
|
| 249 |
+
std::string_view &MangledName,
|
| 250 |
+
std::string_view VariableName);
|
| 251 |
+
VariableSymbolNode *
|
| 252 |
+
demangleRttiBaseClassDescriptorNode(ArenaAllocator &Arena,
|
| 253 |
+
std::string_view &MangledName);
|
| 254 |
+
FunctionSymbolNode *demangleInitFiniStub(std::string_view &MangledName,
|
| 255 |
+
bool IsDestructor);
|
| 256 |
+
|
| 257 |
+
NamedIdentifierNode *demangleSimpleName(std::string_view &MangledName,
|
| 258 |
+
bool Memorize);
|
| 259 |
+
NamedIdentifierNode *
|
| 260 |
+
demangleAnonymousNamespaceName(std::string_view &MangledName);
|
| 261 |
+
NamedIdentifierNode *
|
| 262 |
+
demangleLocallyScopedNamePiece(std::string_view &MangledName);
|
| 263 |
+
EncodedStringLiteralNode *
|
| 264 |
+
demangleStringLiteral(std::string_view &MangledName);
|
| 265 |
+
FunctionSymbolNode *demangleVcallThunkNode(std::string_view &MangledName);
|
| 266 |
+
|
| 267 |
+
std::string_view demangleSimpleString(std::string_view &MangledName,
|
| 268 |
+
bool Memorize);
|
| 269 |
+
|
| 270 |
+
FuncClass demangleFunctionClass(std::string_view &MangledName);
|
| 271 |
+
CallingConv demangleCallingConvention(std::string_view &MangledName);
|
| 272 |
+
StorageClass demangleVariableStorageClass(std::string_view &MangledName);
|
| 273 |
+
bool demangleThrowSpecification(std::string_view &MangledName);
|
| 274 |
+
wchar_t demangleWcharLiteral(std::string_view &MangledName);
|
| 275 |
+
uint8_t demangleCharLiteral(std::string_view &MangledName);
|
| 276 |
+
|
| 277 |
+
std::pair<Qualifiers, bool> demangleQualifiers(std::string_view &MangledName);
|
| 278 |
+
|
| 279 |
+
// Memory allocator.
|
| 280 |
+
ArenaAllocator Arena;
|
| 281 |
+
|
| 282 |
+
// A single type uses one global back-ref table for all function params.
|
| 283 |
+
// This means back-refs can even go "into" other types. Examples:
|
| 284 |
+
//
|
| 285 |
+
// // Second int* is a back-ref to first.
|
| 286 |
+
// void foo(int *, int*);
|
| 287 |
+
//
|
| 288 |
+
// // Second int* is not a back-ref to first (first is not a function param).
|
| 289 |
+
// int* foo(int*);
|
| 290 |
+
//
|
| 291 |
+
// // Second int* is a back-ref to first (ALL function types share the same
|
| 292 |
+
// // back-ref map.
|
| 293 |
+
// using F = void(*)(int*);
|
| 294 |
+
// F G(int *);
|
| 295 |
+
BackrefContext Backrefs;
|
| 296 |
+
};
|
| 297 |
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emangleNodes.h ---------------------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines the AST nodes used in the MSVC demangler.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_DEMANGLE_MICROSOFTDEMANGLENODES_H
|
| 14 |
+
#define LLVM_DEMANGLE_MICROSOFTDEMANGLENODES_H
|
| 15 |
+
|
| 16 |
+
#include <array>
|
| 17 |
+
#include <cstdint>
|
| 18 |
+
#include <string>
|
| 19 |
+
#include <string_view>
|
| 20 |
+
|
| 21 |
+
namespace llvm {
|
| 22 |
+
namespace itanium_demangle {
|
| 23 |
+
class OutputBuffer;
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
using llvm::itanium_demangle::OutputBuffer;
|
| 28 |
+
|
| 29 |
+
namespace llvm {
|
| 30 |
+
namespace ms_demangle {
|
| 31 |
+
|
| 32 |
+
// Storage classes
|
| 33 |
+
enum Qualifiers : uint8_t {
|
| 34 |
+
Q_None = 0,
|
| 35 |
+
Q_Const = 1 << 0,
|
| 36 |
+
Q_Volatile = 1 << 1,
|
| 37 |
+
Q_Far = 1 << 2,
|
| 38 |
+
Q_Huge = 1 << 3,
|
| 39 |
+
Q_Unaligned = 1 << 4,
|
| 40 |
+
Q_Restrict = 1 << 5,
|
| 41 |
+
Q_Pointer64 = 1 << 6
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
enum class StorageClass : uint8_t {
|
| 45 |
+
None,
|
| 46 |
+
PrivateStatic,
|
| 47 |
+
ProtectedStatic,
|
| 48 |
+
PublicStatic,
|
| 49 |
+
Global,
|
| 50 |
+
FunctionLocalStatic,
|
| 51 |
+
};
|
| 52 |
+
|
| 53 |
+
enum class PointerAffinity { None, Pointer, Reference, RValueReference };
|
| 54 |
+
enum class FunctionRefQualifier { None, Reference, RValueReference };
|
| 55 |
+
|
| 56 |
+
// Calling conventions
|
| 57 |
+
enum class CallingConv : uint8_t {
|
| 58 |
+
None,
|
| 59 |
+
Cdecl,
|
| 60 |
+
Pascal,
|
| 61 |
+
Thiscall,
|
| 62 |
+
Stdcall,
|
| 63 |
+
Fastcall,
|
| 64 |
+
Clrcall,
|
| 65 |
+
Eabi,
|
| 66 |
+
Vectorcall,
|
| 67 |
+
Regcall,
|
| 68 |
+
Swift, // Clang-only
|
| 69 |
+
SwiftAsync, // Clang-only
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
|
| 73 |
+
|
| 74 |
+
enum OutputFlags {
|
| 75 |
+
OF_Default = 0,
|
| 76 |
+
OF_NoCallingConvention = 1,
|
| 77 |
+
OF_NoTagSpecifier = 2,
|
| 78 |
+
OF_NoAccessSpecifier = 4,
|
| 79 |
+
OF_NoMemberType = 8,
|
| 80 |
+
OF_NoReturnType = 16,
|
| 81 |
+
OF_NoVariableType = 32,
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
// Types
|
| 85 |
+
enum class PrimitiveKind {
|
| 86 |
+
Void,
|
| 87 |
+
Bool,
|
| 88 |
+
Char,
|
| 89 |
+
Schar,
|
| 90 |
+
Uchar,
|
| 91 |
+
Char8,
|
| 92 |
+
Char16,
|
| 93 |
+
Char32,
|
| 94 |
+
Short,
|
| 95 |
+
Ushort,
|
| 96 |
+
Int,
|
| 97 |
+
Uint,
|
| 98 |
+
Long,
|
| 99 |
+
Ulong,
|
| 100 |
+
Int64,
|
| 101 |
+
Uint64,
|
| 102 |
+
Wchar,
|
| 103 |
+
Float,
|
| 104 |
+
Double,
|
| 105 |
+
Ldouble,
|
| 106 |
+
Nullptr,
|
| 107 |
+
Auto,
|
| 108 |
+
DecltypeAuto,
|
| 109 |
+
};
|
| 110 |
+
|
| 111 |
+
enum class CharKind {
|
| 112 |
+
Char,
|
| 113 |
+
Char16,
|
| 114 |
+
Char32,
|
| 115 |
+
Wchar,
|
| 116 |
+
};
|
| 117 |
+
|
| 118 |
+
enum class IntrinsicFunctionKind : uint8_t {
|
| 119 |
+
None,
|
| 120 |
+
New, // ?2 # operator new
|
| 121 |
+
Delete, // ?3 # operator delete
|
| 122 |
+
Assign, // ?4 # operator=
|
| 123 |
+
RightShift, // ?5 # operator>>
|
| 124 |
+
LeftShift, // ?6 # operator<<
|
| 125 |
+
LogicalNot, // ?7 # operator!
|
| 126 |
+
Equals, // ?8 # operator==
|
| 127 |
+
NotEquals, // ?9 # operator!=
|
| 128 |
+
ArraySubscript, // ?A # operator[]
|
| 129 |
+
Pointer, // ?C # operator->
|
| 130 |
+
Dereference, // ?D # operator*
|
| 131 |
+
Increment, // ?E # operator++
|
| 132 |
+
Decrement, // ?F # operator--
|
| 133 |
+
Minus, // ?G # operator-
|
| 134 |
+
Plus, // ?H # operator+
|
| 135 |
+
BitwiseAnd, // ?I # operator&
|
| 136 |
+
MemberPointer, // ?J # operator->*
|
| 137 |
+
Divide, // ?K # operator/
|
| 138 |
+
Modulus, // ?L # operator%
|
| 139 |
+
LessThan, // ?M operator<
|
| 140 |
+
LessThanEqual, // ?N operator<=
|
| 141 |
+
GreaterThan, // ?O operator>
|
| 142 |
+
GreaterThanEqual, // ?P operator>=
|
| 143 |
+
Comma, // ?Q operator,
|
| 144 |
+
Parens, // ?R operator()
|
| 145 |
+
BitwiseNot, // ?S operator~
|
| 146 |
+
BitwiseXor, // ?T operator^
|
| 147 |
+
BitwiseOr, // ?U operator|
|
| 148 |
+
LogicalAnd, // ?V operator&&
|
| 149 |
+
LogicalOr, // ?W operator||
|
| 150 |
+
TimesEqual, // ?X operator*=
|
| 151 |
+
PlusEqual, // ?Y operator+=
|
| 152 |
+
MinusEqual, // ?Z operator-=
|
| 153 |
+
DivEqual, // ?_0 operator/=
|
| 154 |
+
ModEqual, // ?_1 operator%=
|
| 155 |
+
RshEqual, // ?_2 operator>>=
|
| 156 |
+
LshEqual, // ?_3 operator<<=
|
| 157 |
+
BitwiseAndEqual, // ?_4 operator&=
|
| 158 |
+
BitwiseOrEqual, // ?_5 operator|=
|
| 159 |
+
BitwiseXorEqual, // ?_6 operator^=
|
| 160 |
+
VbaseDtor, // ?_D # vbase destructor
|
| 161 |
+
VecDelDtor, // ?_E # vector deleting destructor
|
| 162 |
+
DefaultCtorClosure, // ?_F # default constructor closure
|
| 163 |
+
ScalarDelDtor, // ?_G # scalar deleting destructor
|
| 164 |
+
VecCtorIter, // ?_H # vector constructor iterator
|
| 165 |
+
VecDtorIter, // ?_I # vector destructor iterator
|
| 166 |
+
VecVbaseCtorIter, // ?_J # vector vbase constructor iterator
|
| 167 |
+
VdispMap, // ?_K # virtual displacement map
|
| 168 |
+
EHVecCtorIter, // ?_L # eh vector constructor iterator
|
| 169 |
+
EHVecDtorIter, // ?_M # eh vector destructor iterator
|
| 170 |
+
EHVecVbaseCtorIter, // ?_N # eh vector vbase constructor iterator
|
| 171 |
+
CopyCtorClosure, // ?_O # copy constructor closure
|
| 172 |
+
LocalVftableCtorClosure, // ?_T # local vftable constructor closure
|
| 173 |
+
ArrayNew, // ?_U operator new[]
|
| 174 |
+
ArrayDelete, // ?_V operator delete[]
|
| 175 |
+
ManVectorCtorIter, // ?__A managed vector ctor iterator
|
| 176 |
+
ManVectorDtorIter, // ?__B managed vector dtor iterator
|
| 177 |
+
EHVectorCopyCtorIter, // ?__C EH vector copy ctor iterator
|
| 178 |
+
EHVectorVbaseCopyCtorIter, // ?__D EH vector vbase copy ctor iterator
|
| 179 |
+
VectorCopyCtorIter, // ?__G vector copy constructor iterator
|
| 180 |
+
VectorVbaseCopyCtorIter, // ?__H vector vbase copy constructor iterator
|
| 181 |
+
ManVectorVbaseCopyCtorIter, // ?__I managed vector vbase copy constructor
|
| 182 |
+
CoAwait, // ?__L operator co_await
|
| 183 |
+
Spaceship, // ?__M operator<=>
|
| 184 |
+
MaxIntrinsic
|
| 185 |
+
};
|
| 186 |
+
|
| 187 |
+
enum class SpecialIntrinsicKind {
|
| 188 |
+
None,
|
| 189 |
+
Vftable,
|
| 190 |
+
Vbtable,
|
| 191 |
+
Typeof,
|
| 192 |
+
VcallThunk,
|
| 193 |
+
LocalStaticGuard,
|
| 194 |
+
StringLiteralSymbol,
|
| 195 |
+
UdtReturning,
|
| 196 |
+
Unknown,
|
| 197 |
+
DynamicInitializer,
|
| 198 |
+
DynamicAtexitDestructor,
|
| 199 |
+
RttiTypeDescriptor,
|
| 200 |
+
RttiBaseClassDescriptor,
|
| 201 |
+
RttiBaseClassArray,
|
| 202 |
+
RttiClassHierarchyDescriptor,
|
| 203 |
+
RttiCompleteObjLocator,
|
| 204 |
+
LocalVftable,
|
| 205 |
+
LocalStaticThreadGuard,
|
| 206 |
+
};
|
| 207 |
+
|
| 208 |
+
// Function classes
|
| 209 |
+
enum FuncClass : uint16_t {
|
| 210 |
+
FC_None = 0,
|
| 211 |
+
FC_Public = 1 << 0,
|
| 212 |
+
FC_Protected = 1 << 1,
|
| 213 |
+
FC_Private = 1 << 2,
|
| 214 |
+
FC_Global = 1 << 3,
|
| 215 |
+
FC_Static = 1 << 4,
|
| 216 |
+
FC_Virtual = 1 << 5,
|
| 217 |
+
FC_Far = 1 << 6,
|
| 218 |
+
FC_ExternC = 1 << 7,
|
| 219 |
+
FC_NoParameterList = 1 << 8,
|
| 220 |
+
FC_VirtualThisAdjust = 1 << 9,
|
| 221 |
+
FC_VirtualThisAdjustEx = 1 << 10,
|
| 222 |
+
FC_StaticThisAdjust = 1 << 11,
|
| 223 |
+
};
|
| 224 |
+
|
| 225 |
+
enum class TagKind { Class, Struct, Union, Enum };
|
| 226 |
+
|
| 227 |
+
enum class NodeKind {
|
| 228 |
+
Unknown,
|
| 229 |
+
Md5Symbol,
|
| 230 |
+
PrimitiveType,
|
| 231 |
+
FunctionSignature,
|
| 232 |
+
Identifier,
|
| 233 |
+
NamedIdentifier,
|
| 234 |
+
VcallThunkIdentifier,
|
| 235 |
+
LocalStaticGuardIdentifier,
|
| 236 |
+
IntrinsicFunctionIdentifier,
|
| 237 |
+
ConversionOperatorIdentifier,
|
| 238 |
+
DynamicStructorIdentifier,
|
| 239 |
+
StructorIdentifier,
|
| 240 |
+
LiteralOperatorIdentifier,
|
| 241 |
+
ThunkSignature,
|
| 242 |
+
PointerType,
|
| 243 |
+
TagType,
|
| 244 |
+
ArrayType,
|
| 245 |
+
Custom,
|
| 246 |
+
IntrinsicType,
|
| 247 |
+
NodeArray,
|
| 248 |
+
QualifiedName,
|
| 249 |
+
TemplateParameterReference,
|
| 250 |
+
EncodedStringLiteral,
|
| 251 |
+
IntegerLiteral,
|
| 252 |
+
RttiBaseClassDescriptor,
|
| 253 |
+
LocalStaticGuardVariable,
|
| 254 |
+
FunctionSymbol,
|
| 255 |
+
VariableSymbol,
|
| 256 |
+
SpecialTableSymbol,
|
| 257 |
+
PointerAuthQualifier,
|
| 258 |
+
};
|
| 259 |
+
|
| 260 |
+
struct Node {
|
| 261 |
+
explicit Node(NodeKind K) : Kind(K) {}
|
| 262 |
+
virtual ~Node() = default;
|
| 263 |
+
|
| 264 |
+
NodeKind kind() const { return Kind; }
|
| 265 |
+
|
| 266 |
+
virtual void output(OutputBuffer &OB, OutputFlags Flags) const = 0;
|
| 267 |
+
|
| 268 |
+
std::string toString(OutputFlags Flags = OF_Default) const;
|
| 269 |
+
|
| 270 |
+
private:
|
| 271 |
+
NodeKind Kind;
|
| 272 |
+
};
|
| 273 |
+
|
| 274 |
+
struct TypeNode;
|
| 275 |
+
struct PrimitiveTypeNode;
|
| 276 |
+
struct FunctionSignatureNode;
|
| 277 |
+
struct IdentifierNode;
|
| 278 |
+
struct NamedIdentifierNode;
|
| 279 |
+
struct VcallThunkIdentifierNode;
|
| 280 |
+
struct IntrinsicFunctionIdentifierNode;
|
| 281 |
+
struct LiteralOperatorIdentifierNode;
|
| 282 |
+
struct ConversionOperatorIdentifierNode;
|
| 283 |
+
struct StructorIdentifierNode;
|
| 284 |
+
struct ThunkSignatureNode;
|
| 285 |
+
struct PointerTypeNode;
|
| 286 |
+
struct ArrayTypeNode;
|
| 287 |
+
struct TagTypeNode;
|
| 288 |
+
struct NodeArrayNode;
|
| 289 |
+
struct QualifiedNameNode;
|
| 290 |
+
struct TemplateParameterReferenceNode;
|
| 291 |
+
struct EncodedStringLiteralNode;
|
| 292 |
+
struct IntegerLiteralNode;
|
| 293 |
+
struct RttiBaseClassDescriptorNode;
|
| 294 |
+
struct LocalStaticGuardVariableNode;
|
| 295 |
+
struct SymbolNode;
|
| 296 |
+
struct FunctionSymbolNode;
|
| 297 |
+
struct VariableSymbolNode;
|
| 298 |
+
struct SpecialTableSymbolNode;
|
| 299 |
+
struct PointerAuthQualifierNode;
|
| 300 |
+
|
| 301 |
+
struct TypeNode : public Node {
|
| 302 |
+
explicit TypeNode(NodeKind K) : Node(K) {}
|
| 303 |
+
|
| 304 |
+
virtual void outputPre(OutputBuffer &OB, OutputFlags Flags) const = 0;
|
| 305 |
+
virtual void outputPost(OutputBuffer &OB, OutputFlags Flags) const = 0;
|
| 306 |
+
|
| 307 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override {
|
| 308 |
+
outputPre(OB, Flags);
|
| 309 |
+
outputPost(OB, Flags);
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
Qualifiers Quals = Q_None;
|
| 313 |
+
};
|
| 314 |
+
|
| 315 |
+
struct PrimitiveTypeNode : public TypeNode {
|
| 316 |
+
explicit PrimitiveTypeNode(PrimitiveKind K)
|
| 317 |
+
: TypeNode(NodeKind::PrimitiveType), PrimKind(K) {}
|
| 318 |
+
|
| 319 |
+
void outputPre(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 320 |
+
void outputPost(OutputBuffer &OB, OutputFlags Flags) const override {}
|
| 321 |
+
|
| 322 |
+
PrimitiveKind PrimKind;
|
| 323 |
+
};
|
| 324 |
+
|
| 325 |
+
struct FunctionSignatureNode : public TypeNode {
|
| 326 |
+
explicit FunctionSignatureNode(NodeKind K) : TypeNode(K) {}
|
| 327 |
+
FunctionSignatureNode() : TypeNode(NodeKind::FunctionSignature) {}
|
| 328 |
+
|
| 329 |
+
void outputPre(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 330 |
+
void outputPost(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 331 |
+
|
| 332 |
+
// Valid if this FunctionTypeNode is the Pointee of a PointerType or
|
| 333 |
+
// MemberPointerType.
|
| 334 |
+
PointerAffinity Affinity = PointerAffinity::None;
|
| 335 |
+
|
| 336 |
+
// The function's calling convention.
|
| 337 |
+
CallingConv CallConvention = CallingConv::None;
|
| 338 |
+
|
| 339 |
+
// Function flags (global, public, etc)
|
| 340 |
+
FuncClass FunctionClass = FC_Global;
|
| 341 |
+
|
| 342 |
+
FunctionRefQualifier RefQualifier = FunctionRefQualifier::None;
|
| 343 |
+
|
| 344 |
+
// The return type of the function.
|
| 345 |
+
TypeNode *ReturnType = nullptr;
|
| 346 |
+
|
| 347 |
+
// True if this is a C-style ... varargs function.
|
| 348 |
+
bool IsVariadic = false;
|
| 349 |
+
|
| 350 |
+
// Function parameters
|
| 351 |
+
NodeArrayNode *Params = nullptr;
|
| 352 |
+
|
| 353 |
+
// True if the function type is noexcept.
|
| 354 |
+
bool IsNoexcept = false;
|
| 355 |
+
};
|
| 356 |
+
|
| 357 |
+
struct IdentifierNode : public Node {
|
| 358 |
+
explicit IdentifierNode(NodeKind K) : Node(K) {}
|
| 359 |
+
|
| 360 |
+
NodeArrayNode *TemplateParams = nullptr;
|
| 361 |
+
|
| 362 |
+
protected:
|
| 363 |
+
void outputTemplateParameters(OutputBuffer &OB, OutputFlags Flags) const;
|
| 364 |
+
};
|
| 365 |
+
|
| 366 |
+
struct VcallThunkIdentifierNode : public IdentifierNode {
|
| 367 |
+
VcallThunkIdentifierNode() : IdentifierNode(NodeKind::VcallThunkIdentifier) {}
|
| 368 |
+
|
| 369 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 370 |
+
|
| 371 |
+
uint64_t OffsetInVTable = 0;
|
| 372 |
+
};
|
| 373 |
+
|
| 374 |
+
struct DynamicStructorIdentifierNode : public IdentifierNode {
|
| 375 |
+
DynamicStructorIdentifierNode()
|
| 376 |
+
: IdentifierNode(NodeKind::DynamicStructorIdentifier) {}
|
| 377 |
+
|
| 378 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 379 |
+
|
| 380 |
+
VariableSymbolNode *Variable = nullptr;
|
| 381 |
+
QualifiedNameNode *Name = nullptr;
|
| 382 |
+
bool IsDestructor = false;
|
| 383 |
+
};
|
| 384 |
+
|
| 385 |
+
struct NamedIdentifierNode : public IdentifierNode {
|
| 386 |
+
NamedIdentifierNode() : IdentifierNode(NodeKind::NamedIdentifier) {}
|
| 387 |
+
|
| 388 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 389 |
+
|
| 390 |
+
std::string_view Name;
|
| 391 |
+
};
|
| 392 |
+
|
| 393 |
+
struct IntrinsicFunctionIdentifierNode : public IdentifierNode {
|
| 394 |
+
explicit IntrinsicFunctionIdentifierNode(IntrinsicFunctionKind Operator)
|
| 395 |
+
: IdentifierNode(NodeKind::IntrinsicFunctionIdentifier),
|
| 396 |
+
Operator(Operator) {}
|
| 397 |
+
|
| 398 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 399 |
+
|
| 400 |
+
IntrinsicFunctionKind Operator;
|
| 401 |
+
};
|
| 402 |
+
|
| 403 |
+
struct LiteralOperatorIdentifierNode : public IdentifierNode {
|
| 404 |
+
LiteralOperatorIdentifierNode()
|
| 405 |
+
: IdentifierNode(NodeKind::LiteralOperatorIdentifier) {}
|
| 406 |
+
|
| 407 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 408 |
+
|
| 409 |
+
std::string_view Name;
|
| 410 |
+
};
|
| 411 |
+
|
| 412 |
+
struct LocalStaticGuardIdentifierNode : public IdentifierNode {
|
| 413 |
+
LocalStaticGuardIdentifierNode()
|
| 414 |
+
: IdentifierNode(NodeKind::LocalStaticGuardIdentifier) {}
|
| 415 |
+
|
| 416 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 417 |
+
|
| 418 |
+
bool IsThread = false;
|
| 419 |
+
uint32_t ScopeIndex = 0;
|
| 420 |
+
};
|
| 421 |
+
|
| 422 |
+
struct ConversionOperatorIdentifierNode : public IdentifierNode {
|
| 423 |
+
ConversionOperatorIdentifierNode()
|
| 424 |
+
: IdentifierNode(NodeKind::ConversionOperatorIdentifier) {}
|
| 425 |
+
|
| 426 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 427 |
+
|
| 428 |
+
// The type that this operator converts too.
|
| 429 |
+
TypeNode *TargetType = nullptr;
|
| 430 |
+
};
|
| 431 |
+
|
| 432 |
+
struct StructorIdentifierNode : public IdentifierNode {
|
| 433 |
+
StructorIdentifierNode() : IdentifierNode(NodeKind::StructorIdentifier) {}
|
| 434 |
+
explicit StructorIdentifierNode(bool IsDestructor)
|
| 435 |
+
: IdentifierNode(NodeKind::StructorIdentifier),
|
| 436 |
+
IsDestructor(IsDestructor) {}
|
| 437 |
+
|
| 438 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 439 |
+
|
| 440 |
+
// The name of the class that this is a structor of.
|
| 441 |
+
IdentifierNode *Class = nullptr;
|
| 442 |
+
bool IsDestructor = false;
|
| 443 |
+
};
|
| 444 |
+
|
| 445 |
+
struct ThunkSignatureNode : public FunctionSignatureNode {
|
| 446 |
+
ThunkSignatureNode() : FunctionSignatureNode(NodeKind::ThunkSignature) {}
|
| 447 |
+
|
| 448 |
+
void outputPre(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 449 |
+
void outputPost(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 450 |
+
|
| 451 |
+
struct ThisAdjustor {
|
| 452 |
+
uint32_t StaticOffset = 0;
|
| 453 |
+
int32_t VBPtrOffset = 0;
|
| 454 |
+
int32_t VBOffsetOffset = 0;
|
| 455 |
+
int32_t VtordispOffset = 0;
|
| 456 |
+
};
|
| 457 |
+
|
| 458 |
+
ThisAdjustor ThisAdjust;
|
| 459 |
+
};
|
| 460 |
+
|
| 461 |
+
struct PointerTypeNode : public TypeNode {
|
| 462 |
+
PointerTypeNode() : TypeNode(NodeKind::PointerType) {}
|
| 463 |
+
void outputPre(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 464 |
+
void outputPost(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 465 |
+
|
| 466 |
+
// Is this a pointer, reference, or rvalue-reference?
|
| 467 |
+
PointerAffinity Affinity = PointerAffinity::None;
|
| 468 |
+
|
| 469 |
+
// If this is a member pointer, this is the class that the member is in.
|
| 470 |
+
QualifiedNameNode *ClassParent = nullptr;
|
| 471 |
+
|
| 472 |
+
PointerAuthQualifierNode *PointerAuthQualifier = nullptr;
|
| 473 |
+
|
| 474 |
+
// Represents a type X in "a pointer to X", "a reference to X", or
|
| 475 |
+
// "rvalue-reference to X"
|
| 476 |
+
TypeNode *Pointee = nullptr;
|
| 477 |
+
};
|
| 478 |
+
|
| 479 |
+
struct TagTypeNode : public TypeNode {
|
| 480 |
+
explicit TagTypeNode(TagKind Tag) : TypeNode(NodeKind::TagType), Tag(Tag) {}
|
| 481 |
+
|
| 482 |
+
void outputPre(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 483 |
+
void outputPost(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 484 |
+
|
| 485 |
+
QualifiedNameNode *QualifiedName = nullptr;
|
| 486 |
+
TagKind Tag;
|
| 487 |
+
};
|
| 488 |
+
|
| 489 |
+
struct ArrayTypeNode : public TypeNode {
|
| 490 |
+
ArrayTypeNode() : TypeNode(NodeKind::ArrayType) {}
|
| 491 |
+
|
| 492 |
+
void outputPre(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 493 |
+
void outputPost(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 494 |
+
|
| 495 |
+
void outputDimensionsImpl(OutputBuffer &OB, OutputFlags Flags) const;
|
| 496 |
+
void outputOneDimension(OutputBuffer &OB, OutputFlags Flags, Node *N) const;
|
| 497 |
+
|
| 498 |
+
// A list of array dimensions. e.g. [3,4,5] in `int Foo[3][4][5]`
|
| 499 |
+
NodeArrayNode *Dimensions = nullptr;
|
| 500 |
+
|
| 501 |
+
// The type of array element.
|
| 502 |
+
TypeNode *ElementType = nullptr;
|
| 503 |
+
};
|
| 504 |
+
|
| 505 |
+
struct IntrinsicNode : public TypeNode {
|
| 506 |
+
IntrinsicNode() : TypeNode(NodeKind::IntrinsicType) {}
|
| 507 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override {}
|
| 508 |
+
};
|
| 509 |
+
|
| 510 |
+
struct CustomTypeNode : public TypeNode {
|
| 511 |
+
CustomTypeNode() : TypeNode(NodeKind::Custom) {}
|
| 512 |
+
|
| 513 |
+
void outputPre(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 514 |
+
void outputPost(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 515 |
+
|
| 516 |
+
IdentifierNode *Identifier = nullptr;
|
| 517 |
+
};
|
| 518 |
+
|
| 519 |
+
struct NodeArrayNode : public Node {
|
| 520 |
+
NodeArrayNode() : Node(NodeKind::NodeArray) {}
|
| 521 |
+
|
| 522 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 523 |
+
|
| 524 |
+
void output(OutputBuffer &OB, OutputFlags Flags,
|
| 525 |
+
std::string_view Separator) const;
|
| 526 |
+
|
| 527 |
+
Node **Nodes = nullptr;
|
| 528 |
+
size_t Count = 0;
|
| 529 |
+
};
|
| 530 |
+
|
| 531 |
+
struct QualifiedNameNode : public Node {
|
| 532 |
+
QualifiedNameNode() : Node(NodeKind::QualifiedName) {}
|
| 533 |
+
|
| 534 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 535 |
+
|
| 536 |
+
NodeArrayNode *Components = nullptr;
|
| 537 |
+
|
| 538 |
+
IdentifierNode *getUnqualifiedIdentifier() {
|
| 539 |
+
Node *LastComponent = Components->Nodes[Components->Count - 1];
|
| 540 |
+
return static_cast<IdentifierNode *>(LastComponent);
|
| 541 |
+
}
|
| 542 |
+
};
|
| 543 |
+
|
| 544 |
+
struct TemplateParameterReferenceNode : public Node {
|
| 545 |
+
TemplateParameterReferenceNode()
|
| 546 |
+
: Node(NodeKind::TemplateParameterReference) {}
|
| 547 |
+
|
| 548 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 549 |
+
|
| 550 |
+
SymbolNode *Symbol = nullptr;
|
| 551 |
+
|
| 552 |
+
int ThunkOffsetCount = 0;
|
| 553 |
+
std::array<int64_t, 3> ThunkOffsets;
|
| 554 |
+
PointerAffinity Affinity = PointerAffinity::None;
|
| 555 |
+
bool IsMemberPointer = false;
|
| 556 |
+
};
|
| 557 |
+
|
| 558 |
+
struct IntegerLiteralNode : public Node {
|
| 559 |
+
IntegerLiteralNode() : Node(NodeKind::IntegerLiteral) {}
|
| 560 |
+
IntegerLiteralNode(uint64_t Value, bool IsNegative)
|
| 561 |
+
: Node(NodeKind::IntegerLiteral), Value(Value), IsNegative(IsNegative) {}
|
| 562 |
+
|
| 563 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 564 |
+
|
| 565 |
+
uint64_t Value = 0;
|
| 566 |
+
bool IsNegative = false;
|
| 567 |
+
};
|
| 568 |
+
|
| 569 |
+
struct RttiBaseClassDescriptorNode : public IdentifierNode {
|
| 570 |
+
RttiBaseClassDescriptorNode()
|
| 571 |
+
: IdentifierNode(NodeKind::RttiBaseClassDescriptor) {}
|
| 572 |
+
|
| 573 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 574 |
+
|
| 575 |
+
uint32_t NVOffset = 0;
|
| 576 |
+
int32_t VBPtrOffset = 0;
|
| 577 |
+
uint32_t VBTableOffset = 0;
|
| 578 |
+
uint32_t Flags = 0;
|
| 579 |
+
};
|
| 580 |
+
|
| 581 |
+
struct SymbolNode : public Node {
|
| 582 |
+
explicit SymbolNode(NodeKind K) : Node(K) {}
|
| 583 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 584 |
+
QualifiedNameNode *Name = nullptr;
|
| 585 |
+
};
|
| 586 |
+
|
| 587 |
+
struct SpecialTableSymbolNode : public SymbolNode {
|
| 588 |
+
explicit SpecialTableSymbolNode()
|
| 589 |
+
: SymbolNode(NodeKind::SpecialTableSymbol) {}
|
| 590 |
+
|
| 591 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 592 |
+
QualifiedNameNode *TargetName = nullptr;
|
| 593 |
+
Qualifiers Quals = Qualifiers::Q_None;
|
| 594 |
+
};
|
| 595 |
+
|
| 596 |
+
struct LocalStaticGuardVariableNode : public SymbolNode {
|
| 597 |
+
LocalStaticGuardVariableNode()
|
| 598 |
+
: SymbolNode(NodeKind::LocalStaticGuardVariable) {}
|
| 599 |
+
|
| 600 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 601 |
+
|
| 602 |
+
bool IsVisible = false;
|
| 603 |
+
};
|
| 604 |
+
|
| 605 |
+
struct EncodedStringLiteralNode : public SymbolNode {
|
| 606 |
+
EncodedStringLiteralNode() : SymbolNode(NodeKind::EncodedStringLiteral) {}
|
| 607 |
+
|
| 608 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 609 |
+
|
| 610 |
+
std::string_view DecodedString;
|
| 611 |
+
bool IsTruncated = false;
|
| 612 |
+
CharKind Char = CharKind::Char;
|
| 613 |
+
};
|
| 614 |
+
|
| 615 |
+
struct VariableSymbolNode : public SymbolNode {
|
| 616 |
+
VariableSymbolNode() : SymbolNode(NodeKind::VariableSymbol) {}
|
| 617 |
+
|
| 618 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 619 |
+
|
| 620 |
+
StorageClass SC = StorageClass::None;
|
| 621 |
+
TypeNode *Type = nullptr;
|
| 622 |
+
};
|
| 623 |
+
|
| 624 |
+
struct FunctionSymbolNode : public SymbolNode {
|
| 625 |
+
FunctionSymbolNode() : SymbolNode(NodeKind::FunctionSymbol) {}
|
| 626 |
+
|
| 627 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 628 |
+
|
| 629 |
+
FunctionSignatureNode *Signature = nullptr;
|
| 630 |
+
};
|
| 631 |
+
|
| 632 |
+
struct PointerAuthQualifierNode : public Node {
|
| 633 |
+
PointerAuthQualifierNode() : Node(NodeKind::PointerAuthQualifier) {}
|
| 634 |
+
|
| 635 |
+
// __ptrauth takes three arguments:
|
| 636 |
+
// - key
|
| 637 |
+
// - isAddressDiscriminated
|
| 638 |
+
// - extra discriminator
|
| 639 |
+
static constexpr unsigned NumArgs = 3;
|
| 640 |
+
typedef std::array<uint64_t, NumArgs> ArgArray;
|
| 641 |
+
|
| 642 |
+
void output(OutputBuffer &OB, OutputFlags Flags) const override;
|
| 643 |
+
|
| 644 |
+
// List of arguments.
|
| 645 |
+
NodeArrayNode *Components = nullptr;
|
| 646 |
+
};
|
| 647 |
+
|
| 648 |
+
} // namespace ms_demangle
|
| 649 |
+
} // namespace llvm
|
| 650 |
+
|
| 651 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Demangle/StringViewExtras.h
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===--- StringViewExtras.h ----------*- mode:c++;eval:(read-only-mode) -*-===//
|
| 2 |
+
// Do not edit! See README.txt.
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// There are two copies of this file in the source tree. The one under
|
| 10 |
+
// libcxxabi is the original and the one under llvm is the copy. Use
|
| 11 |
+
// cp-to-llvm.sh to update the copy. See README.txt for more details.
|
| 12 |
+
//
|
| 13 |
+
//===----------------------------------------------------------------------===//
|
| 14 |
+
|
| 15 |
+
#ifndef DEMANGLE_STRINGVIEW_H
|
| 16 |
+
#define DEMANGLE_STRINGVIEW_H
|
| 17 |
+
|
| 18 |
+
#include "DemangleConfig.h"
|
| 19 |
+
|
| 20 |
+
#include <string_view>
|
| 21 |
+
|
| 22 |
+
DEMANGLE_NAMESPACE_BEGIN
|
| 23 |
+
|
| 24 |
+
inline bool starts_with(std::string_view self, char C) noexcept {
|
| 25 |
+
return !self.empty() && *self.begin() == C;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
inline bool starts_with(std::string_view haystack,
|
| 29 |
+
std::string_view needle) noexcept {
|
| 30 |
+
if (needle.size() > haystack.size())
|
| 31 |
+
return false;
|
| 32 |
+
haystack.remove_suffix(haystack.size() - needle.size());
|
| 33 |
+
return haystack == needle;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
DEMANGLE_NAMESPACE_END
|
| 37 |
+
|
| 38 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Demangle/Utility.h
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===--- Utility.h -------------------*- mode:c++;eval:(read-only-mode) -*-===//
|
| 2 |
+
// Do not edit! See README.txt.
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// Provide some utility classes for use in the demangler.
|
| 10 |
+
// There are two copies of this file in the source tree. The one in libcxxabi
|
| 11 |
+
// is the original and the one in llvm is the copy. Use cp-to-llvm.sh to update
|
| 12 |
+
// the copy. See README.txt for more details.
|
| 13 |
+
//
|
| 14 |
+
//===----------------------------------------------------------------------===//
|
| 15 |
+
|
| 16 |
+
#ifndef DEMANGLE_UTILITY_H
|
| 17 |
+
#define DEMANGLE_UTILITY_H
|
| 18 |
+
|
| 19 |
+
#include "DemangleConfig.h"
|
| 20 |
+
|
| 21 |
+
#include <array>
|
| 22 |
+
#include <cstdint>
|
| 23 |
+
#include <cstdlib>
|
| 24 |
+
#include <cstring>
|
| 25 |
+
#include <limits>
|
| 26 |
+
#include <string_view>
|
| 27 |
+
|
| 28 |
+
DEMANGLE_NAMESPACE_BEGIN
|
| 29 |
+
|
| 30 |
+
class Node;
|
| 31 |
+
|
| 32 |
+
// Stream that AST nodes write their string representation into after the AST
|
| 33 |
+
// has been parsed.
|
| 34 |
+
class OutputBuffer {
|
| 35 |
+
char *Buffer = nullptr;
|
| 36 |
+
size_t CurrentPosition = 0;
|
| 37 |
+
size_t BufferCapacity = 0;
|
| 38 |
+
|
| 39 |
+
// Ensure there are at least N more positions in the buffer.
|
| 40 |
+
void grow(size_t N) {
|
| 41 |
+
size_t Need = N + CurrentPosition;
|
| 42 |
+
if (Need > BufferCapacity) {
|
| 43 |
+
// Reduce the number of reallocations, with a bit of hysteresis. The
|
| 44 |
+
// number here is chosen so the first allocation will more-than-likely not
|
| 45 |
+
// allocate more than 1K.
|
| 46 |
+
Need += 1024 - 32;
|
| 47 |
+
BufferCapacity *= 2;
|
| 48 |
+
if (BufferCapacity < Need)
|
| 49 |
+
BufferCapacity = Need;
|
| 50 |
+
Buffer = static_cast<char *>(std::realloc(Buffer, BufferCapacity));
|
| 51 |
+
if (Buffer == nullptr)
|
| 52 |
+
std::abort();
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
OutputBuffer &writeUnsigned(uint64_t N, bool isNeg = false) {
|
| 57 |
+
std::array<char, 21> Temp;
|
| 58 |
+
char *TempPtr = Temp.data() + Temp.size();
|
| 59 |
+
|
| 60 |
+
// Output at least one character.
|
| 61 |
+
do {
|
| 62 |
+
*--TempPtr = char('0' + N % 10);
|
| 63 |
+
N /= 10;
|
| 64 |
+
} while (N);
|
| 65 |
+
|
| 66 |
+
// Add negative sign.
|
| 67 |
+
if (isNeg)
|
| 68 |
+
*--TempPtr = '-';
|
| 69 |
+
|
| 70 |
+
return operator+=(
|
| 71 |
+
std::string_view(TempPtr, Temp.data() + Temp.size() - TempPtr));
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
public:
|
| 75 |
+
OutputBuffer(char *StartBuf, size_t Size)
|
| 76 |
+
: Buffer(StartBuf), BufferCapacity(Size) {}
|
| 77 |
+
OutputBuffer(char *StartBuf, size_t *SizePtr)
|
| 78 |
+
: OutputBuffer(StartBuf, StartBuf ? *SizePtr : 0) {}
|
| 79 |
+
OutputBuffer() = default;
|
| 80 |
+
// Non-copyable
|
| 81 |
+
OutputBuffer(const OutputBuffer &) = delete;
|
| 82 |
+
OutputBuffer &operator=(const OutputBuffer &) = delete;
|
| 83 |
+
|
| 84 |
+
virtual ~OutputBuffer() {}
|
| 85 |
+
|
| 86 |
+
operator std::string_view() const {
|
| 87 |
+
return std::string_view(Buffer, CurrentPosition);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/// Called by the demangler when printing the demangle tree. By
|
| 91 |
+
/// default calls into \c Node::print{Left|Right} but can be overriden
|
| 92 |
+
/// by clients to track additional state when printing the demangled name.
|
| 93 |
+
virtual void printLeft(const Node &N);
|
| 94 |
+
virtual void printRight(const Node &N);
|
| 95 |
+
|
| 96 |
+
/// Called when we write to this object anywhere other than the end.
|
| 97 |
+
virtual void notifyInsertion(size_t /*Position*/, size_t /*Count*/) {}
|
| 98 |
+
|
| 99 |
+
/// Called when we make the \c CurrentPosition of this object smaller.
|
| 100 |
+
virtual void notifyDeletion(size_t /*OldPos*/, size_t /*NewPos*/) {}
|
| 101 |
+
|
| 102 |
+
/// If a ParameterPackExpansion (or similar type) is encountered, the offset
|
| 103 |
+
/// into the pack that we're currently printing.
|
| 104 |
+
unsigned CurrentPackIndex = std::numeric_limits<unsigned>::max();
|
| 105 |
+
unsigned CurrentPackMax = std::numeric_limits<unsigned>::max();
|
| 106 |
+
|
| 107 |
+
/// When zero, we're printing template args and '>' needs to be parenthesized.
|
| 108 |
+
/// Use a counter so we can simply increment inside parentheses.
|
| 109 |
+
unsigned GtIsGt = 1;
|
| 110 |
+
|
| 111 |
+
bool isGtInsideTemplateArgs() const { return GtIsGt == 0; }
|
| 112 |
+
|
| 113 |
+
void printOpen(char Open = '(') {
|
| 114 |
+
GtIsGt++;
|
| 115 |
+
*this += Open;
|
| 116 |
+
}
|
| 117 |
+
void printClose(char Close = ')') {
|
| 118 |
+
GtIsGt--;
|
| 119 |
+
*this += Close;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
OutputBuffer &operator+=(std::string_view R) {
|
| 123 |
+
if (size_t Size = R.size()) {
|
| 124 |
+
grow(Size);
|
| 125 |
+
std::memcpy(Buffer + CurrentPosition, &*R.begin(), Size);
|
| 126 |
+
CurrentPosition += Size;
|
| 127 |
+
}
|
| 128 |
+
return *this;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
OutputBuffer &operator+=(char C) {
|
| 132 |
+
grow(1);
|
| 133 |
+
Buffer[CurrentPosition++] = C;
|
| 134 |
+
return *this;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
OutputBuffer &prepend(std::string_view R) {
|
| 138 |
+
size_t Size = R.size();
|
| 139 |
+
if (!Size)
|
| 140 |
+
return *this;
|
| 141 |
+
|
| 142 |
+
grow(Size);
|
| 143 |
+
std::memmove(Buffer + Size, Buffer, CurrentPosition);
|
| 144 |
+
std::memcpy(Buffer, &*R.begin(), Size);
|
| 145 |
+
CurrentPosition += Size;
|
| 146 |
+
|
| 147 |
+
notifyInsertion(/*Position=*/0, /*Count=*/Size);
|
| 148 |
+
|
| 149 |
+
return *this;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
OutputBuffer &operator<<(std::string_view R) { return (*this += R); }
|
| 153 |
+
|
| 154 |
+
OutputBuffer &operator<<(char C) { return (*this += C); }
|
| 155 |
+
|
| 156 |
+
OutputBuffer &operator<<(long long N) {
|
| 157 |
+
return writeUnsigned(static_cast<unsigned long long>(std::abs(N)), N < 0);
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
OutputBuffer &operator<<(unsigned long long N) {
|
| 161 |
+
return writeUnsigned(N, false);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
OutputBuffer &operator<<(long N) {
|
| 165 |
+
return this->operator<<(static_cast<long long>(N));
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
OutputBuffer &operator<<(unsigned long N) {
|
| 169 |
+
return this->operator<<(static_cast<unsigned long long>(N));
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
OutputBuffer &operator<<(int N) {
|
| 173 |
+
return this->operator<<(static_cast<long long>(N));
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
OutputBuffer &operator<<(unsigned int N) {
|
| 177 |
+
return this->operator<<(static_cast<unsigned long long>(N));
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
void insert(size_t Pos, const char *S, size_t N) {
|
| 181 |
+
DEMANGLE_ASSERT(Pos <= CurrentPosition, "");
|
| 182 |
+
if (N == 0)
|
| 183 |
+
return;
|
| 184 |
+
|
| 185 |
+
grow(N);
|
| 186 |
+
std::memmove(Buffer + Pos + N, Buffer + Pos, CurrentPosition - Pos);
|
| 187 |
+
std::memcpy(Buffer + Pos, S, N);
|
| 188 |
+
CurrentPosition += N;
|
| 189 |
+
|
| 190 |
+
notifyInsertion(Pos, N);
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
size_t getCurrentPosition() const { return CurrentPosition; }
|
| 194 |
+
void setCurrentPosition(size_t NewPos) {
|
| 195 |
+
notifyDeletion(CurrentPosition, NewPos);
|
| 196 |
+
CurrentPosition = NewPos;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
char back() const {
|
| 200 |
+
DEMANGLE_ASSERT(CurrentPosition, "");
|
| 201 |
+
return Buffer[CurrentPosition - 1];
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
bool empty() const { return CurrentPosition == 0; }
|
| 205 |
+
|
| 206 |
+
char *getBuffer() { return Buffer; }
|
| 207 |
+
char *getBufferEnd() { return Buffer + CurrentPosition - 1; }
|
| 208 |
+
size_t getBufferCapacity() const { return BufferCapacity; }
|
| 209 |
+
};
|
| 210 |
+
|
| 211 |
+
template <class T> class ScopedOverride {
|
| 212 |
+
T &Loc;
|
| 213 |
+
T Original;
|
| 214 |
+
|
| 215 |
+
public:
|
| 216 |
+
ScopedOverride(T &Loc_) : ScopedOverride(Loc_, Loc_) {}
|
| 217 |
+
|
| 218 |
+
ScopedOverride(T &Loc_, T NewVal) : Loc(Loc_), Original(Loc_) {
|
| 219 |
+
Loc_ = std::move(NewVal);
|
| 220 |
+
}
|
| 221 |
+
~ScopedOverride() { Loc = std::move(Original); }
|
| 222 |
+
|
| 223 |
+
ScopedOverride(const ScopedOverride &) = delete;
|
| 224 |
+
ScopedOverride &operator=(const ScopedOverride &) = delete;
|
| 225 |
+
};
|
| 226 |
+
|
| 227 |
+
DEMANGLE_NAMESPACE_END
|
| 228 |
+
|
| 229 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/InitializePasses.h
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/InitializePasses.h - Initialize All Passes ----------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file contains the declarations for the pass initialization routines
|
| 10 |
+
// for the entire LLVM project.
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#ifndef LLVM_INITIALIZEPASSES_H
|
| 15 |
+
#define LLVM_INITIALIZEPASSES_H
|
| 16 |
+
|
| 17 |
+
namespace llvm {
|
| 18 |
+
|
| 19 |
+
class PassRegistry;
|
| 20 |
+
|
| 21 |
+
/// Initialize all passes linked into the Core library.
|
| 22 |
+
void initializeCore(PassRegistry &);
|
| 23 |
+
|
| 24 |
+
/// Initialize all passes linked into the TransformUtils library.
|
| 25 |
+
void initializeTransformUtils(PassRegistry &);
|
| 26 |
+
|
| 27 |
+
/// Initialize all passes linked into the ScalarOpts library.
|
| 28 |
+
void initializeScalarOpts(PassRegistry &);
|
| 29 |
+
|
| 30 |
+
/// Initialize all passes linked into the Vectorize library.
|
| 31 |
+
void initializeVectorization(PassRegistry &);
|
| 32 |
+
|
| 33 |
+
/// Initialize all passes linked into the InstCombine library.
|
| 34 |
+
void initializeInstCombine(PassRegistry &);
|
| 35 |
+
|
| 36 |
+
/// Initialize all passes linked into the IPO library.
|
| 37 |
+
void initializeIPO(PassRegistry &);
|
| 38 |
+
|
| 39 |
+
/// Initialize all passes linked into the Analysis library.
|
| 40 |
+
void initializeAnalysis(PassRegistry &);
|
| 41 |
+
|
| 42 |
+
/// Initialize all passes linked into the CodeGen library.
|
| 43 |
+
void initializeCodeGen(PassRegistry &);
|
| 44 |
+
|
| 45 |
+
/// Initialize all passes linked into the GlobalISel library.
|
| 46 |
+
void initializeGlobalISel(PassRegistry &);
|
| 47 |
+
|
| 48 |
+
/// Initialize all passes linked into the CodeGen library.
|
| 49 |
+
void initializeTarget(PassRegistry &);
|
| 50 |
+
|
| 51 |
+
void initializeAAResultsWrapperPassPass(PassRegistry &);
|
| 52 |
+
void initializeAlwaysInlinerLegacyPassPass(PassRegistry &);
|
| 53 |
+
void initializeAssignmentTrackingAnalysisPass(PassRegistry &);
|
| 54 |
+
void initializeAssumptionCacheTrackerPass(PassRegistry &);
|
| 55 |
+
void initializeAtomicExpandLegacyPass(PassRegistry &);
|
| 56 |
+
void initializeBasicBlockPathCloningPass(PassRegistry &);
|
| 57 |
+
void initializeBasicBlockSectionsProfileReaderWrapperPassPass(PassRegistry &);
|
| 58 |
+
void initializeBasicBlockSectionsPass(PassRegistry &);
|
| 59 |
+
void initializeBarrierNoopPass(PassRegistry &);
|
| 60 |
+
void initializeBasicAAWrapperPassPass(PassRegistry &);
|
| 61 |
+
void initializeBlockFrequencyInfoWrapperPassPass(PassRegistry &);
|
| 62 |
+
void initializeBranchFolderLegacyPass(PassRegistry &);
|
| 63 |
+
void initializeBranchProbabilityInfoWrapperPassPass(PassRegistry &);
|
| 64 |
+
void initializeBranchRelaxationLegacyPass(PassRegistry &);
|
| 65 |
+
void initializeBreakCriticalEdgesPass(PassRegistry &);
|
| 66 |
+
void initializeBreakFalseDepsPass(PassRegistry &);
|
| 67 |
+
void initializeCanonicalizeFreezeInLoopsPass(PassRegistry &);
|
| 68 |
+
void initializeCFGSimplifyPassPass(PassRegistry &);
|
| 69 |
+
void initializeCFGuardPass(PassRegistry &);
|
| 70 |
+
void initializeCFGuardLongjmpPass(PassRegistry &);
|
| 71 |
+
void initializeCFIFixupPass(PassRegistry &);
|
| 72 |
+
void initializeCFIInstrInserterPass(PassRegistry &);
|
| 73 |
+
void initializeCallBrPreparePass(PassRegistry &);
|
| 74 |
+
void initializeCallGraphDOTPrinterPass(PassRegistry &);
|
| 75 |
+
void initializeCallGraphViewerPass(PassRegistry &);
|
| 76 |
+
void initializeCallGraphWrapperPassPass(PassRegistry &);
|
| 77 |
+
void initializeCheckDebugMachineModulePass(PassRegistry &);
|
| 78 |
+
void initializeCodeGenPrepareLegacyPassPass(PassRegistry &);
|
| 79 |
+
void initializeComplexDeinterleavingLegacyPassPass(PassRegistry &);
|
| 80 |
+
void initializeConstantHoistingLegacyPassPass(PassRegistry &);
|
| 81 |
+
void initializeCycleInfoWrapperPassPass(PassRegistry &);
|
| 82 |
+
void initializeDAEPass(PassRegistry &);
|
| 83 |
+
void initializeDAHPass(PassRegistry &);
|
| 84 |
+
void initializeDCELegacyPassPass(PassRegistry &);
|
| 85 |
+
void initializeDXILMetadataAnalysisWrapperPassPass(PassRegistry &);
|
| 86 |
+
void initializeDXILMetadataAnalysisWrapperPrinterPass(PassRegistry &);
|
| 87 |
+
void initializeDXILResourceBindingWrapperPassPass(PassRegistry &);
|
| 88 |
+
void initializeDXILResourceImplicitBindingLegacyPass(PassRegistry &);
|
| 89 |
+
void initializeDXILResourceTypeWrapperPassPass(PassRegistry &);
|
| 90 |
+
void initializeDXILResourceWrapperPassPass(PassRegistry &);
|
| 91 |
+
void initializeDeadMachineInstructionElimPass(PassRegistry &);
|
| 92 |
+
void initializeDebugifyMachineModulePass(PassRegistry &);
|
| 93 |
+
void initializeDependenceAnalysisWrapperPassPass(PassRegistry &);
|
| 94 |
+
void initializeDetectDeadLanesLegacyPass(PassRegistry &);
|
| 95 |
+
void initializeDomOnlyPrinterWrapperPassPass(PassRegistry &);
|
| 96 |
+
void initializeDomOnlyViewerWrapperPassPass(PassRegistry &);
|
| 97 |
+
void initializeDomPrinterWrapperPassPass(PassRegistry &);
|
| 98 |
+
void initializeDomViewerWrapperPassPass(PassRegistry &);
|
| 99 |
+
void initializeDominanceFrontierWrapperPassPass(PassRegistry &);
|
| 100 |
+
void initializeDominatorTreeWrapperPassPass(PassRegistry &);
|
| 101 |
+
void initializeDwarfEHPrepareLegacyPassPass(PassRegistry &);
|
| 102 |
+
void initializeEarlyCSELegacyPassPass(PassRegistry &);
|
| 103 |
+
void initializeEarlyCSEMemSSALegacyPassPass(PassRegistry &);
|
| 104 |
+
void initializeEarlyIfConverterLegacyPass(PassRegistry &);
|
| 105 |
+
void initializeEarlyIfPredicatorPass(PassRegistry &);
|
| 106 |
+
void initializeEarlyMachineLICMPass(PassRegistry &);
|
| 107 |
+
void initializeEarlyTailDuplicateLegacyPass(PassRegistry &);
|
| 108 |
+
void initializeEdgeBundlesWrapperLegacyPass(PassRegistry &);
|
| 109 |
+
void initializeEHContGuardTargetsPass(PassRegistry &);
|
| 110 |
+
void initializeExpandFpLegacyPassPass(PassRegistry &);
|
| 111 |
+
void initializeExpandLargeDivRemLegacyPassPass(PassRegistry &);
|
| 112 |
+
void initializeExpandMemCmpLegacyPassPass(PassRegistry &);
|
| 113 |
+
void initializeExpandPostRALegacyPass(PassRegistry &);
|
| 114 |
+
void initializeExpandReductionsPass(PassRegistry &);
|
| 115 |
+
void initializeExpandVariadicsPass(PassRegistry &);
|
| 116 |
+
void initializeExternalAAWrapperPassPass(PassRegistry &);
|
| 117 |
+
void initializeFEntryInserterLegacyPass(PassRegistry &);
|
| 118 |
+
void initializeFinalizeISelPass(PassRegistry &);
|
| 119 |
+
void initializeFinalizeMachineBundlesPass(PassRegistry &);
|
| 120 |
+
void initializeFixIrreduciblePass(PassRegistry &);
|
| 121 |
+
void initializeFixupStatepointCallerSavedLegacyPass(PassRegistry &);
|
| 122 |
+
void initializeFlattenCFGLegacyPassPass(PassRegistry &);
|
| 123 |
+
void initializeFuncletLayoutPass(PassRegistry &);
|
| 124 |
+
void initializeGCEmptyBasicBlocksPass(PassRegistry &);
|
| 125 |
+
void initializeGCMachineCodeAnalysisPass(PassRegistry &);
|
| 126 |
+
void initializeGCModuleInfoPass(PassRegistry &);
|
| 127 |
+
void initializeGVNLegacyPassPass(PassRegistry &);
|
| 128 |
+
void initializeGlobalMergeFuncPassWrapperPass(PassRegistry &);
|
| 129 |
+
void initializeGlobalMergePass(PassRegistry &);
|
| 130 |
+
void initializeGlobalsAAWrapperPassPass(PassRegistry &);
|
| 131 |
+
void initializeHardwareLoopsLegacyPass(PassRegistry &);
|
| 132 |
+
void initializeMIRProfileLoaderPassPass(PassRegistry &);
|
| 133 |
+
void initializeIRSimilarityIdentifierWrapperPassPass(PassRegistry &);
|
| 134 |
+
void initializeIRTranslatorPass(PassRegistry &);
|
| 135 |
+
void initializeIVUsersWrapperPassPass(PassRegistry &);
|
| 136 |
+
void initializeIfConverterPass(PassRegistry &);
|
| 137 |
+
void initializeImmutableModuleSummaryIndexWrapperPassPass(PassRegistry &);
|
| 138 |
+
void initializeImplicitNullChecksPass(PassRegistry &);
|
| 139 |
+
void initializeIndirectBrExpandLegacyPassPass(PassRegistry &);
|
| 140 |
+
void initializeInferAddressSpacesPass(PassRegistry &);
|
| 141 |
+
void initializeInstSimplifyLegacyPassPass(PassRegistry &);
|
| 142 |
+
void initializeInstructionCombiningPassPass(PassRegistry &);
|
| 143 |
+
void initializeInstructionSelectPass(PassRegistry &);
|
| 144 |
+
void initializeInterleavedAccessPass(PassRegistry &);
|
| 145 |
+
void initializeInterleavedLoadCombinePass(PassRegistry &);
|
| 146 |
+
void initializeJMCInstrumenterPass(PassRegistry &);
|
| 147 |
+
void initializeKCFIPass(PassRegistry &);
|
| 148 |
+
void initializeLCSSAVerificationPassPass(PassRegistry &);
|
| 149 |
+
void initializeLCSSAWrapperPassPass(PassRegistry &);
|
| 150 |
+
void initializeLazyBFIPassPass(PassRegistry &);
|
| 151 |
+
void initializeLazyBlockFrequencyInfoPassPass(PassRegistry &);
|
| 152 |
+
void initializeLazyBranchProbabilityInfoPassPass(PassRegistry &);
|
| 153 |
+
void initializeLazyMachineBlockFrequencyInfoPassPass(PassRegistry &);
|
| 154 |
+
void initializeLazyValueInfoWrapperPassPass(PassRegistry &);
|
| 155 |
+
void initializeLegacyLICMPassPass(PassRegistry &);
|
| 156 |
+
void initializeLegalizerPass(PassRegistry &);
|
| 157 |
+
void initializeGISelCSEAnalysisWrapperPassPass(PassRegistry &);
|
| 158 |
+
void initializeGISelValueTrackingAnalysisLegacyPass(PassRegistry &);
|
| 159 |
+
void initializeLiveDebugValuesLegacyPass(PassRegistry &);
|
| 160 |
+
void initializeLiveDebugVariablesWrapperLegacyPass(PassRegistry &);
|
| 161 |
+
void initializeLiveIntervalsWrapperPassPass(PassRegistry &);
|
| 162 |
+
void initializeLiveRangeShrinkPass(PassRegistry &);
|
| 163 |
+
void initializeLiveRegMatrixWrapperLegacyPass(PassRegistry &);
|
| 164 |
+
void initializeLiveStacksWrapperLegacyPass(PassRegistry &);
|
| 165 |
+
void initializeLiveVariablesWrapperPassPass(PassRegistry &);
|
| 166 |
+
void initializeLoadStoreOptPass(PassRegistry &);
|
| 167 |
+
void initializeLoadStoreVectorizerLegacyPassPass(PassRegistry &);
|
| 168 |
+
void initializeLocalStackSlotPassPass(PassRegistry &);
|
| 169 |
+
void initializeLocalizerPass(PassRegistry &);
|
| 170 |
+
void initializeLoopDataPrefetchLegacyPassPass(PassRegistry &);
|
| 171 |
+
void initializeLoopExtractorLegacyPassPass(PassRegistry &);
|
| 172 |
+
void initializeLoopInfoWrapperPassPass(PassRegistry &);
|
| 173 |
+
void initializeLoopPassPass(PassRegistry &);
|
| 174 |
+
void initializeLoopSimplifyPass(PassRegistry &);
|
| 175 |
+
void initializeLoopStrengthReducePass(PassRegistry &);
|
| 176 |
+
void initializeLoopTermFoldPass(PassRegistry &);
|
| 177 |
+
void initializeLoopUnrollPass(PassRegistry &);
|
| 178 |
+
void initializeLowerAtomicLegacyPassPass(PassRegistry &);
|
| 179 |
+
void initializeLowerEmuTLSPass(PassRegistry &);
|
| 180 |
+
void initializeLowerGlobalDtorsLegacyPassPass(PassRegistry &);
|
| 181 |
+
void initializeLowerIntrinsicsPass(PassRegistry &);
|
| 182 |
+
void initializeLowerInvokeLegacyPassPass(PassRegistry &);
|
| 183 |
+
void initializeLowerSwitchLegacyPassPass(PassRegistry &);
|
| 184 |
+
void initializeKCFIPass(PassRegistry &);
|
| 185 |
+
void initializeMIRAddFSDiscriminatorsPass(PassRegistry &);
|
| 186 |
+
void initializeMIRCanonicalizerPass(PassRegistry &);
|
| 187 |
+
void initializeMIRNamerPass(PassRegistry &);
|
| 188 |
+
void initializeMIRPrintingPassPass(PassRegistry &);
|
| 189 |
+
void initializeMachineBlockFrequencyInfoWrapperPassPass(PassRegistry &);
|
| 190 |
+
void initializeMachineBlockPlacementLegacyPass(PassRegistry &);
|
| 191 |
+
void initializeMachineBlockPlacementStatsLegacyPass(PassRegistry &);
|
| 192 |
+
void initializeMachineBranchProbabilityInfoWrapperPassPass(PassRegistry &);
|
| 193 |
+
void initializeMachineCFGPrinterPass(PassRegistry &);
|
| 194 |
+
void initializeMachineCSELegacyPass(PassRegistry &);
|
| 195 |
+
void initializeMachineCombinerPass(PassRegistry &);
|
| 196 |
+
void initializeMachineCopyPropagationLegacyPass(PassRegistry &);
|
| 197 |
+
void initializeMachineCycleInfoPrinterLegacyPass(PassRegistry &);
|
| 198 |
+
void initializeMachineCycleInfoWrapperPassPass(PassRegistry &);
|
| 199 |
+
void initializeMachineDominanceFrontierPass(PassRegistry &);
|
| 200 |
+
void initializeMachineDominatorTreeWrapperPassPass(PassRegistry &);
|
| 201 |
+
void initializeMachineFunctionPrinterPassPass(PassRegistry &);
|
| 202 |
+
void initializeMachineFunctionSplitterPass(PassRegistry &);
|
| 203 |
+
void initializeMachineLateInstrsCleanupLegacyPass(PassRegistry &);
|
| 204 |
+
void initializeMachineLICMPass(PassRegistry &);
|
| 205 |
+
void initializeMachineLoopInfoWrapperPassPass(PassRegistry &);
|
| 206 |
+
void initializeMachineModuleInfoWrapperPassPass(PassRegistry &);
|
| 207 |
+
void initializeMachineOptimizationRemarkEmitterPassPass(PassRegistry &);
|
| 208 |
+
void initializeMachineOutlinerPass(PassRegistry &);
|
| 209 |
+
void initializeStaticDataProfileInfoWrapperPassPass(PassRegistry &);
|
| 210 |
+
void initializeStaticDataAnnotatorPass(PassRegistry &);
|
| 211 |
+
void initializeMachinePipelinerPass(PassRegistry &);
|
| 212 |
+
void initializeMachinePostDominatorTreeWrapperPassPass(PassRegistry &);
|
| 213 |
+
void initializeMachineRegionInfoPassPass(PassRegistry &);
|
| 214 |
+
void initializeMachineSanitizerBinaryMetadataLegacyPass(PassRegistry &);
|
| 215 |
+
void initializeMachineSchedulerLegacyPass(PassRegistry &);
|
| 216 |
+
void initializeMachineSinkingLegacyPass(PassRegistry &);
|
| 217 |
+
void initializeMachineTraceMetricsWrapperPassPass(PassRegistry &);
|
| 218 |
+
void initializeMachineUniformityInfoPrinterPassPass(PassRegistry &);
|
| 219 |
+
void initializeMachineUniformityAnalysisPassPass(PassRegistry &);
|
| 220 |
+
void initializeMachineVerifierLegacyPassPass(PassRegistry &);
|
| 221 |
+
void initializeMemoryDependenceWrapperPassPass(PassRegistry &);
|
| 222 |
+
void initializeMemorySSAWrapperPassPass(PassRegistry &);
|
| 223 |
+
void initializeMergeICmpsLegacyPassPass(PassRegistry &);
|
| 224 |
+
void initializeModuleSummaryIndexWrapperPassPass(PassRegistry &);
|
| 225 |
+
void initializeModuloScheduleTestPass(PassRegistry &);
|
| 226 |
+
void initializeNaryReassociateLegacyPassPass(PassRegistry &);
|
| 227 |
+
void initializeObjCARCContractLegacyPassPass(PassRegistry &);
|
| 228 |
+
void initializeOptimizationRemarkEmitterWrapperPassPass(PassRegistry &);
|
| 229 |
+
void initializeOptimizePHIsLegacyPass(PassRegistry &);
|
| 230 |
+
void initializePEILegacyPass(PassRegistry &);
|
| 231 |
+
void initializePHIEliminationPass(PassRegistry &);
|
| 232 |
+
void initializePartiallyInlineLibCallsLegacyPassPass(PassRegistry &);
|
| 233 |
+
void initializePatchableFunctionLegacyPass(PassRegistry &);
|
| 234 |
+
void initializePeepholeOptimizerLegacyPass(PassRegistry &);
|
| 235 |
+
void initializePhiValuesWrapperPassPass(PassRegistry &);
|
| 236 |
+
void initializePhysicalRegisterUsageInfoWrapperLegacyPass(PassRegistry &);
|
| 237 |
+
void initializePlaceBackedgeSafepointsLegacyPassPass(PassRegistry &);
|
| 238 |
+
void initializePostDomOnlyPrinterWrapperPassPass(PassRegistry &);
|
| 239 |
+
void initializePostDomOnlyViewerWrapperPassPass(PassRegistry &);
|
| 240 |
+
void initializePostDomPrinterWrapperPassPass(PassRegistry &);
|
| 241 |
+
void initializePostDomViewerWrapperPassPass(PassRegistry &);
|
| 242 |
+
void initializePostDominatorTreeWrapperPassPass(PassRegistry &);
|
| 243 |
+
void initializePostInlineEntryExitInstrumenterPass(PassRegistry &);
|
| 244 |
+
void initializePostMachineSchedulerLegacyPass(PassRegistry &);
|
| 245 |
+
void initializePostRAHazardRecognizerLegacyPass(PassRegistry &);
|
| 246 |
+
void initializePostRAMachineSinkingPass(PassRegistry &);
|
| 247 |
+
void initializePostRASchedulerLegacyPass(PassRegistry &);
|
| 248 |
+
void initializePreISelIntrinsicLoweringLegacyPassPass(PassRegistry &);
|
| 249 |
+
void initializePrintFunctionPassWrapperPass(PassRegistry &);
|
| 250 |
+
void initializePrintModulePassWrapperPass(PassRegistry &);
|
| 251 |
+
void initializeProcessImplicitDefsPass(PassRegistry &);
|
| 252 |
+
void initializeProfileSummaryInfoWrapperPassPass(PassRegistry &);
|
| 253 |
+
void initializePromoteLegacyPassPass(PassRegistry &);
|
| 254 |
+
void initializeRABasicPass(PassRegistry &);
|
| 255 |
+
void initializePseudoProbeInserterPass(PassRegistry &);
|
| 256 |
+
void initializeRAGreedyLegacyPass(PassRegistry &);
|
| 257 |
+
void initializeReachingDefAnalysisPass(PassRegistry &);
|
| 258 |
+
void initializeReassociateLegacyPassPass(PassRegistry &);
|
| 259 |
+
void initializeRegAllocEvictionAdvisorAnalysisLegacyPass(PassRegistry &);
|
| 260 |
+
void initializeRegAllocFastPass(PassRegistry &);
|
| 261 |
+
void initializeRegAllocPriorityAdvisorAnalysisLegacyPass(PassRegistry &);
|
| 262 |
+
void initializeRegAllocScoringPass(PassRegistry &);
|
| 263 |
+
void initializeRegBankSelectPass(PassRegistry &);
|
| 264 |
+
void initializeRegToMemWrapperPassPass(PassRegistry &);
|
| 265 |
+
void initializeRegUsageInfoCollectorLegacyPass(PassRegistry &);
|
| 266 |
+
void initializeRegUsageInfoPropagationLegacyPass(PassRegistry &);
|
| 267 |
+
void initializeRegionInfoPassPass(PassRegistry &);
|
| 268 |
+
void initializeRegionOnlyPrinterPass(PassRegistry &);
|
| 269 |
+
void initializeRegionOnlyViewerPass(PassRegistry &);
|
| 270 |
+
void initializeRegionPrinterPass(PassRegistry &);
|
| 271 |
+
void initializeRegionViewerPass(PassRegistry &);
|
| 272 |
+
void initializeRegisterCoalescerLegacyPass(PassRegistry &);
|
| 273 |
+
void initializeRemoveLoadsIntoFakeUsesLegacyPass(PassRegistry &);
|
| 274 |
+
void initializeRemoveRedundantDebugValuesLegacyPass(PassRegistry &);
|
| 275 |
+
void initializeRenameIndependentSubregsLegacyPass(PassRegistry &);
|
| 276 |
+
void initializeReplaceWithVeclibLegacyPass(PassRegistry &);
|
| 277 |
+
void initializeResetMachineFunctionPass(PassRegistry &);
|
| 278 |
+
void initializeSCEVAAWrapperPassPass(PassRegistry &);
|
| 279 |
+
void initializeSROALegacyPassPass(PassRegistry &);
|
| 280 |
+
void initializeSafeStackLegacyPassPass(PassRegistry &);
|
| 281 |
+
void initializeSafepointIRVerifierPass(PassRegistry &);
|
| 282 |
+
void initializeSelectOptimizePass(PassRegistry &);
|
| 283 |
+
void initializeScalarEvolutionWrapperPassPass(PassRegistry &);
|
| 284 |
+
void initializeScalarizeMaskedMemIntrinLegacyPassPass(PassRegistry &);
|
| 285 |
+
void initializeScalarizerLegacyPassPass(PassRegistry &);
|
| 286 |
+
void initializeScavengerTestPass(PassRegistry &);
|
| 287 |
+
void initializeScopedNoAliasAAWrapperPassPass(PassRegistry &);
|
| 288 |
+
void initializeSeparateConstOffsetFromGEPLegacyPassPass(PassRegistry &);
|
| 289 |
+
void initializeShadowStackGCLoweringPass(PassRegistry &);
|
| 290 |
+
void initializeShrinkWrapLegacyPass(PassRegistry &);
|
| 291 |
+
void initializeSingleLoopExtractorPass(PassRegistry &);
|
| 292 |
+
void initializeSinkingLegacyPassPass(PassRegistry &);
|
| 293 |
+
void initializeSjLjEHPreparePass(PassRegistry &);
|
| 294 |
+
void initializeSlotIndexesWrapperPassPass(PassRegistry &);
|
| 295 |
+
void initializeSpeculativeExecutionLegacyPassPass(PassRegistry &);
|
| 296 |
+
void initializeSpillPlacementWrapperLegacyPass(PassRegistry &);
|
| 297 |
+
void initializeStackColoringLegacyPass(PassRegistry &);
|
| 298 |
+
void initializeStackFrameLayoutAnalysisLegacyPass(PassRegistry &);
|
| 299 |
+
void initializeStaticDataSplitterPass(PassRegistry &);
|
| 300 |
+
void initializeStackMapLivenessPass(PassRegistry &);
|
| 301 |
+
void initializeStackProtectorPass(PassRegistry &);
|
| 302 |
+
void initializeStackSafetyGlobalInfoWrapperPassPass(PassRegistry &);
|
| 303 |
+
void initializeStackSafetyInfoWrapperPassPass(PassRegistry &);
|
| 304 |
+
void initializeStackSlotColoringLegacyPass(PassRegistry &);
|
| 305 |
+
void initializeStraightLineStrengthReduceLegacyPassPass(PassRegistry &);
|
| 306 |
+
void initializeStripDebugMachineModulePass(PassRegistry &);
|
| 307 |
+
void initializeStructurizeCFGLegacyPassPass(PassRegistry &);
|
| 308 |
+
void initializeTailCallElimPass(PassRegistry &);
|
| 309 |
+
void initializeTailDuplicateLegacyPass(PassRegistry &);
|
| 310 |
+
void initializeTargetLibraryInfoWrapperPassPass(PassRegistry &);
|
| 311 |
+
void initializeTargetPassConfigPass(PassRegistry &);
|
| 312 |
+
void initializeTargetTransformInfoWrapperPassPass(PassRegistry &);
|
| 313 |
+
void initializeTwoAddressInstructionLegacyPassPass(PassRegistry &);
|
| 314 |
+
void initializeTypeBasedAAWrapperPassPass(PassRegistry &);
|
| 315 |
+
void initializeTypePromotionLegacyPass(PassRegistry &);
|
| 316 |
+
void initializeInitUndefPass(PassRegistry &);
|
| 317 |
+
void initializeUniformityInfoWrapperPassPass(PassRegistry &);
|
| 318 |
+
void initializeUnifyLoopExitsLegacyPassPass(PassRegistry &);
|
| 319 |
+
void initializeUnpackMachineBundlesPass(PassRegistry &);
|
| 320 |
+
void initializeUnreachableBlockElimLegacyPassPass(PassRegistry &);
|
| 321 |
+
void initializeUnreachableMachineBlockElimLegacyPass(PassRegistry &);
|
| 322 |
+
void initializeVerifierLegacyPassPass(PassRegistry &);
|
| 323 |
+
void initializeVirtRegMapWrapperLegacyPass(PassRegistry &);
|
| 324 |
+
void initializeVirtRegRewriterLegacyPass(PassRegistry &);
|
| 325 |
+
void initializeWasmEHPreparePass(PassRegistry &);
|
| 326 |
+
void initializeWinEHPreparePass(PassRegistry &);
|
| 327 |
+
void initializeWriteBitcodePassPass(PassRegistry &);
|
| 328 |
+
void initializeXRayInstrumentationLegacyPass(PassRegistry &);
|
| 329 |
+
|
| 330 |
+
} // end namespace llvm
|
| 331 |
+
|
| 332 |
+
#endif // LLVM_INITIALIZEPASSES_H
|
deps/exla/cache/xla_extension/include/llvm/LinkAllIR.h
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===----- LinkAllIR.h - Reference All VMCore Code --------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This header file pulls in all the object modules of the VMCore library so
|
| 10 |
+
// that tools like llc, opt, and lli can ensure they are linked with all symbols
|
| 11 |
+
// from libVMCore.a It should only be used from a tool's main program.
|
| 12 |
+
//
|
| 13 |
+
//===----------------------------------------------------------------------===//
|
| 14 |
+
|
| 15 |
+
#ifndef LLVM_LINKALLIR_H
|
| 16 |
+
#define LLVM_LINKALLIR_H
|
| 17 |
+
|
| 18 |
+
#include "llvm/BinaryFormat/Dwarf.h"
|
| 19 |
+
#include "llvm/IR/InlineAsm.h"
|
| 20 |
+
#include "llvm/IR/Instructions.h"
|
| 21 |
+
#include "llvm/IR/LLVMContext.h"
|
| 22 |
+
#include "llvm/IR/Module.h"
|
| 23 |
+
#include "llvm/IR/Verifier.h"
|
| 24 |
+
#include "llvm/Support/DynamicLibrary.h"
|
| 25 |
+
#include "llvm/Support/MathExtras.h"
|
| 26 |
+
#include "llvm/Support/Memory.h"
|
| 27 |
+
#include "llvm/Support/Mutex.h"
|
| 28 |
+
#include "llvm/Support/Path.h"
|
| 29 |
+
#include "llvm/Support/Process.h"
|
| 30 |
+
#include "llvm/Support/Program.h"
|
| 31 |
+
#include "llvm/Support/Signals.h"
|
| 32 |
+
#include <cstdlib>
|
| 33 |
+
|
| 34 |
+
namespace {
|
| 35 |
+
struct ForceVMCoreLinking {
|
| 36 |
+
ForceVMCoreLinking() {
|
| 37 |
+
// We must reference VMCore in such a way that compilers will not
|
| 38 |
+
// delete it all as dead code, even with whole program optimization,
|
| 39 |
+
// yet is effectively a NO-OP. As the compiler isn't smart enough
|
| 40 |
+
// to know that getenv() never returns -1, this will do the job.
|
| 41 |
+
// This is so that globals in the translation units where these functions
|
| 42 |
+
// are defined are forced to be initialized, populating various
|
| 43 |
+
// registries.
|
| 44 |
+
if (std::getenv("bar") != (char*) -1)
|
| 45 |
+
return;
|
| 46 |
+
llvm::LLVMContext Context;
|
| 47 |
+
(void)new llvm::Module("", Context);
|
| 48 |
+
(void)new llvm::UnreachableInst(Context);
|
| 49 |
+
(void) llvm::createVerifierPass();
|
| 50 |
+
}
|
| 51 |
+
} ForceVMCoreLinking;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/LinkAllPasses.h
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/LinkAllPasses.h ------------ Reference All Passes ---*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This header file pulls in all transformation and analysis passes for tools
|
| 10 |
+
// like opt and bugpoint that need this functionality.
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#ifndef LLVM_LINKALLPASSES_H
|
| 15 |
+
#define LLVM_LINKALLPASSES_H
|
| 16 |
+
|
| 17 |
+
#include "llvm/ADT/Statistic.h"
|
| 18 |
+
#include "llvm/Analysis/AliasAnalysisEvaluator.h"
|
| 19 |
+
#include "llvm/Analysis/AliasSetTracker.h"
|
| 20 |
+
#include "llvm/Analysis/BasicAliasAnalysis.h"
|
| 21 |
+
#include "llvm/Analysis/CallPrinter.h"
|
| 22 |
+
#include "llvm/Analysis/DXILResource.h"
|
| 23 |
+
#include "llvm/Analysis/DomPrinter.h"
|
| 24 |
+
#include "llvm/Analysis/GlobalsModRef.h"
|
| 25 |
+
#include "llvm/Analysis/Passes.h"
|
| 26 |
+
#include "llvm/Analysis/PostDominators.h"
|
| 27 |
+
#include "llvm/Analysis/RegionPass.h"
|
| 28 |
+
#include "llvm/Analysis/RegionPrinter.h"
|
| 29 |
+
#include "llvm/Analysis/ScalarEvolution.h"
|
| 30 |
+
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
|
| 31 |
+
#include "llvm/Analysis/ScopedNoAliasAA.h"
|
| 32 |
+
#include "llvm/Analysis/TargetLibraryInfo.h"
|
| 33 |
+
#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
|
| 34 |
+
#include "llvm/CodeGen/Passes.h"
|
| 35 |
+
#include "llvm/IR/Function.h"
|
| 36 |
+
#include "llvm/IR/IRPrintingPasses.h"
|
| 37 |
+
#include "llvm/Support/Valgrind.h"
|
| 38 |
+
#include "llvm/Transforms/IPO.h"
|
| 39 |
+
#include "llvm/Transforms/IPO/AlwaysInliner.h"
|
| 40 |
+
#include "llvm/Transforms/InstCombine/InstCombine.h"
|
| 41 |
+
#include "llvm/Transforms/ObjCARC.h"
|
| 42 |
+
#include "llvm/Transforms/Scalar.h"
|
| 43 |
+
#include "llvm/Transforms/Scalar/GVN.h"
|
| 44 |
+
#include "llvm/Transforms/Scalar/Scalarizer.h"
|
| 45 |
+
#include "llvm/Transforms/Utils.h"
|
| 46 |
+
#include "llvm/Transforms/Utils/SymbolRewriter.h"
|
| 47 |
+
#include "llvm/Transforms/Vectorize/LoadStoreVectorizer.h"
|
| 48 |
+
#include <cstdlib>
|
| 49 |
+
|
| 50 |
+
namespace {
|
| 51 |
+
struct ForcePassLinking {
|
| 52 |
+
ForcePassLinking() {
|
| 53 |
+
// We must reference the passes in such a way that compilers will not
|
| 54 |
+
// delete it all as dead code, even with whole program optimization,
|
| 55 |
+
// yet is effectively a NO-OP. As the compiler isn't smart enough
|
| 56 |
+
// to know that getenv() never returns -1, this will do the job.
|
| 57 |
+
// This is so that globals in the translation units where these functions
|
| 58 |
+
// are defined are forced to be initialized, populating various
|
| 59 |
+
// registries.
|
| 60 |
+
if (std::getenv("bar") != (char *)-1)
|
| 61 |
+
return;
|
| 62 |
+
|
| 63 |
+
(void)llvm::createAtomicExpandLegacyPass();
|
| 64 |
+
(void)llvm::createBasicAAWrapperPass();
|
| 65 |
+
(void)llvm::createSCEVAAWrapperPass();
|
| 66 |
+
(void)llvm::createTypeBasedAAWrapperPass();
|
| 67 |
+
(void)llvm::createScopedNoAliasAAWrapperPass();
|
| 68 |
+
(void)llvm::createBreakCriticalEdgesPass();
|
| 69 |
+
(void)llvm::createCallGraphDOTPrinterPass();
|
| 70 |
+
(void)llvm::createCallGraphViewerPass();
|
| 71 |
+
(void)llvm::createCFGSimplificationPass();
|
| 72 |
+
(void)llvm::createStructurizeCFGPass();
|
| 73 |
+
(void)llvm::createDXILResourceWrapperPassPass();
|
| 74 |
+
(void)llvm::createDXILResourceTypeWrapperPassPass();
|
| 75 |
+
(void)llvm::createDeadArgEliminationPass();
|
| 76 |
+
(void)llvm::createDeadCodeEliminationPass();
|
| 77 |
+
(void)llvm::createDependenceAnalysisWrapperPass();
|
| 78 |
+
(void)llvm::createDomOnlyPrinterWrapperPassPass();
|
| 79 |
+
(void)llvm::createDomPrinterWrapperPassPass();
|
| 80 |
+
(void)llvm::createDomOnlyViewerWrapperPassPass();
|
| 81 |
+
(void)llvm::createDomViewerWrapperPassPass();
|
| 82 |
+
(void)llvm::createAlwaysInlinerLegacyPass();
|
| 83 |
+
(void)llvm::createGlobalMergeFuncPass();
|
| 84 |
+
(void)llvm::createGlobalsAAWrapperPass();
|
| 85 |
+
(void)llvm::createInstSimplifyLegacyPass();
|
| 86 |
+
(void)llvm::createInstructionCombiningPass();
|
| 87 |
+
(void)llvm::createJMCInstrumenterPass();
|
| 88 |
+
(void)llvm::createKCFIPass();
|
| 89 |
+
(void)llvm::createLCSSAPass();
|
| 90 |
+
(void)llvm::createLICMPass();
|
| 91 |
+
(void)llvm::createLazyValueInfoPass();
|
| 92 |
+
(void)llvm::createLoopExtractorPass();
|
| 93 |
+
(void)llvm::createLoopSimplifyPass();
|
| 94 |
+
(void)llvm::createLoopStrengthReducePass();
|
| 95 |
+
(void)llvm::createLoopTermFoldPass();
|
| 96 |
+
(void)llvm::createLoopUnrollPass();
|
| 97 |
+
(void)llvm::createLowerGlobalDtorsLegacyPass();
|
| 98 |
+
(void)llvm::createLowerInvokePass();
|
| 99 |
+
(void)llvm::createLowerSwitchPass();
|
| 100 |
+
(void)llvm::createNaryReassociatePass();
|
| 101 |
+
(void)llvm::createObjCARCContractPass();
|
| 102 |
+
(void)llvm::createPromoteMemoryToRegisterPass();
|
| 103 |
+
(void)llvm::createRegToMemWrapperPass();
|
| 104 |
+
(void)llvm::createPostDomOnlyPrinterWrapperPassPass();
|
| 105 |
+
(void)llvm::createPostDomPrinterWrapperPassPass();
|
| 106 |
+
(void)llvm::createPostDomOnlyViewerWrapperPassPass();
|
| 107 |
+
(void)llvm::createPostDomViewerWrapperPassPass();
|
| 108 |
+
(void)llvm::createReassociatePass();
|
| 109 |
+
(void)llvm::createRegionInfoPass();
|
| 110 |
+
(void)llvm::createRegionOnlyPrinterPass();
|
| 111 |
+
(void)llvm::createRegionOnlyViewerPass();
|
| 112 |
+
(void)llvm::createRegionPrinterPass();
|
| 113 |
+
(void)llvm::createRegionViewerPass();
|
| 114 |
+
(void)llvm::createSafeStackPass();
|
| 115 |
+
(void)llvm::createSROAPass();
|
| 116 |
+
(void)llvm::createSingleLoopExtractorPass();
|
| 117 |
+
(void)llvm::createTailCallEliminationPass();
|
| 118 |
+
(void)llvm::createConstantHoistingPass();
|
| 119 |
+
(void)llvm::createCodeGenPrepareLegacyPass();
|
| 120 |
+
(void)llvm::createPostInlineEntryExitInstrumenterPass();
|
| 121 |
+
(void)llvm::createEarlyCSEPass();
|
| 122 |
+
(void)llvm::createGVNPass();
|
| 123 |
+
(void)llvm::createPostDomTree();
|
| 124 |
+
(void)llvm::createMergeICmpsLegacyPass();
|
| 125 |
+
(void)llvm::createExpandLargeDivRemPass();
|
| 126 |
+
(void)llvm::createExpandMemCmpLegacyPass();
|
| 127 |
+
std::string buf;
|
| 128 |
+
llvm::raw_string_ostream os(buf);
|
| 129 |
+
(void)llvm::createPrintModulePass(os);
|
| 130 |
+
(void)llvm::createPrintFunctionPass(os);
|
| 131 |
+
(void)llvm::createSinkingPass();
|
| 132 |
+
(void)llvm::createLowerAtomicPass();
|
| 133 |
+
(void)llvm::createLoadStoreVectorizerPass();
|
| 134 |
+
(void)llvm::createPartiallyInlineLibCallsPass();
|
| 135 |
+
(void)llvm::createScalarizerPass();
|
| 136 |
+
(void)llvm::createSeparateConstOffsetFromGEPPass();
|
| 137 |
+
(void)llvm::createSpeculativeExecutionPass();
|
| 138 |
+
(void)llvm::createSpeculativeExecutionIfHasBranchDivergencePass();
|
| 139 |
+
(void)llvm::createStraightLineStrengthReducePass();
|
| 140 |
+
(void)llvm::createScalarizeMaskedMemIntrinLegacyPass();
|
| 141 |
+
(void)llvm::createHardwareLoopsLegacyPass();
|
| 142 |
+
(void)llvm::createUnifyLoopExitsPass();
|
| 143 |
+
(void)llvm::createFixIrreduciblePass();
|
| 144 |
+
(void)llvm::createSelectOptimizePass();
|
| 145 |
+
|
| 146 |
+
(void)new llvm::ScalarEvolutionWrapperPass();
|
| 147 |
+
llvm::Function::Create(nullptr, llvm::GlobalValue::ExternalLinkage)
|
| 148 |
+
->viewCFGOnly();
|
| 149 |
+
llvm::RGPassManager RGM;
|
| 150 |
+
llvm::TargetLibraryInfoImpl TLII;
|
| 151 |
+
llvm::TargetLibraryInfo TLI(TLII);
|
| 152 |
+
llvm::AliasAnalysis AA(TLI);
|
| 153 |
+
llvm::BatchAAResults BAA(AA);
|
| 154 |
+
llvm::AliasSetTracker X(BAA);
|
| 155 |
+
X.add(llvm::MemoryLocation()); // for -print-alias-sets
|
| 156 |
+
(void)llvm::AreStatisticsEnabled();
|
| 157 |
+
(void)llvm::sys::RunningOnValgrind();
|
| 158 |
+
}
|
| 159 |
+
} ForcePassLinking; // Force link by creating a global definition.
|
| 160 |
+
} // namespace
|
| 161 |
+
|
| 162 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Pass.h
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/Pass.h - Base class for Passes ----------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines a base class that indicates that a specified class is a
|
| 10 |
+
// transformation pass implementation.
|
| 11 |
+
//
|
| 12 |
+
// Passes are designed this way so that it is possible to run passes in a cache
|
| 13 |
+
// and organizationally optimal order without having to specify it at the front
|
| 14 |
+
// end. This allows arbitrary passes to be strung together and have them
|
| 15 |
+
// executed as efficiently as possible.
|
| 16 |
+
//
|
| 17 |
+
// Passes should extend one of the classes below, depending on the guarantees
|
| 18 |
+
// that it can make about what will be modified as it is run. For example, most
|
| 19 |
+
// global optimizations should derive from FunctionPass, because they do not add
|
| 20 |
+
// or delete functions, they operate on the internals of the function.
|
| 21 |
+
//
|
| 22 |
+
// Note that this file #includes PassSupport.h and PassAnalysisSupport.h (at the
|
| 23 |
+
// bottom), so the APIs exposed by these files are also automatically available
|
| 24 |
+
// to all users of this file.
|
| 25 |
+
//
|
| 26 |
+
//===----------------------------------------------------------------------===//
|
| 27 |
+
|
| 28 |
+
#ifndef LLVM_PASS_H
|
| 29 |
+
#define LLVM_PASS_H
|
| 30 |
+
|
| 31 |
+
#ifdef EXPENSIVE_CHECKS
|
| 32 |
+
#include <cstdint>
|
| 33 |
+
#endif
|
| 34 |
+
#include <string>
|
| 35 |
+
|
| 36 |
+
namespace llvm {
|
| 37 |
+
|
| 38 |
+
class AnalysisResolver;
|
| 39 |
+
class AnalysisUsage;
|
| 40 |
+
class Function;
|
| 41 |
+
class ImmutablePass;
|
| 42 |
+
class Module;
|
| 43 |
+
class PassInfo;
|
| 44 |
+
class PMDataManager;
|
| 45 |
+
class PMStack;
|
| 46 |
+
class raw_ostream;
|
| 47 |
+
class StringRef;
|
| 48 |
+
|
| 49 |
+
// AnalysisID - Use the PassInfo to identify a pass...
|
| 50 |
+
using AnalysisID = const void *;
|
| 51 |
+
|
| 52 |
+
/// Different types of internal pass managers. External pass managers
|
| 53 |
+
/// (PassManager and FunctionPassManager) are not represented here.
|
| 54 |
+
/// Ordering of pass manager types is important here.
|
| 55 |
+
enum PassManagerType {
|
| 56 |
+
PMT_Unknown = 0,
|
| 57 |
+
PMT_ModulePassManager = 1, ///< MPPassManager
|
| 58 |
+
PMT_CallGraphPassManager, ///< CGPassManager
|
| 59 |
+
PMT_FunctionPassManager, ///< FPPassManager
|
| 60 |
+
PMT_LoopPassManager, ///< LPPassManager
|
| 61 |
+
PMT_RegionPassManager, ///< RGPassManager
|
| 62 |
+
PMT_Last
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
// Different types of passes.
|
| 66 |
+
enum PassKind {
|
| 67 |
+
PT_Region,
|
| 68 |
+
PT_Loop,
|
| 69 |
+
PT_Function,
|
| 70 |
+
PT_CallGraphSCC,
|
| 71 |
+
PT_Module,
|
| 72 |
+
PT_PassManager
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
/// This enumerates the LLVM full LTO or ThinLTO optimization phases.
|
| 76 |
+
enum class ThinOrFullLTOPhase {
|
| 77 |
+
/// No LTO/ThinLTO behavior needed.
|
| 78 |
+
None,
|
| 79 |
+
/// ThinLTO prelink (summary) phase.
|
| 80 |
+
ThinLTOPreLink,
|
| 81 |
+
/// ThinLTO postlink (backend compile) phase.
|
| 82 |
+
ThinLTOPostLink,
|
| 83 |
+
/// Full LTO prelink phase.
|
| 84 |
+
FullLTOPreLink,
|
| 85 |
+
/// Full LTO postlink (backend compile) phase.
|
| 86 |
+
FullLTOPostLink
|
| 87 |
+
};
|
| 88 |
+
|
| 89 |
+
#ifndef NDEBUG
|
| 90 |
+
const char *to_string(ThinOrFullLTOPhase Phase);
|
| 91 |
+
#endif
|
| 92 |
+
|
| 93 |
+
//===----------------------------------------------------------------------===//
|
| 94 |
+
/// Pass interface - Implemented by all 'passes'. Subclass this if you are an
|
| 95 |
+
/// interprocedural optimization or you do not fit into any of the more
|
| 96 |
+
/// constrained passes described below.
|
| 97 |
+
///
|
| 98 |
+
class Pass {
|
| 99 |
+
AnalysisResolver *Resolver = nullptr; // Used to resolve analysis
|
| 100 |
+
const void *PassID;
|
| 101 |
+
PassKind Kind;
|
| 102 |
+
|
| 103 |
+
public:
|
| 104 |
+
explicit Pass(PassKind K, char &pid) : PassID(&pid), Kind(K) {}
|
| 105 |
+
Pass(const Pass &) = delete;
|
| 106 |
+
Pass &operator=(const Pass &) = delete;
|
| 107 |
+
virtual ~Pass();
|
| 108 |
+
|
| 109 |
+
PassKind getPassKind() const { return Kind; }
|
| 110 |
+
|
| 111 |
+
/// getPassName - Return a nice clean name for a pass. This usually
|
| 112 |
+
/// implemented in terms of the name that is registered by one of the
|
| 113 |
+
/// Registration templates, but can be overloaded directly.
|
| 114 |
+
virtual StringRef getPassName() const;
|
| 115 |
+
|
| 116 |
+
/// getPassID - Return the PassID number that corresponds to this pass.
|
| 117 |
+
AnalysisID getPassID() const {
|
| 118 |
+
return PassID;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/// doInitialization - Virtual method overridden by subclasses to do
|
| 122 |
+
/// any necessary initialization before any pass is run.
|
| 123 |
+
virtual bool doInitialization(Module &) { return false; }
|
| 124 |
+
|
| 125 |
+
/// doFinalization - Virtual method overriden by subclasses to do any
|
| 126 |
+
/// necessary clean up after all passes have run.
|
| 127 |
+
virtual bool doFinalization(Module &) { return false; }
|
| 128 |
+
|
| 129 |
+
/// print - Print out the internal state of the pass. This is called by
|
| 130 |
+
/// Analyze to print out the contents of an analysis. Otherwise it is not
|
| 131 |
+
/// necessary to implement this method. Beware that the module pointer MAY be
|
| 132 |
+
/// null. This automatically forwards to a virtual function that does not
|
| 133 |
+
/// provide the Module* in case the analysis doesn't need it it can just be
|
| 134 |
+
/// ignored.
|
| 135 |
+
virtual void print(raw_ostream &OS, const Module *M) const;
|
| 136 |
+
|
| 137 |
+
void dump() const; // dump - Print to stderr.
|
| 138 |
+
|
| 139 |
+
/// createPrinterPass - Get a Pass appropriate to print the IR this
|
| 140 |
+
/// pass operates on (Module, Function or MachineFunction).
|
| 141 |
+
virtual Pass *createPrinterPass(raw_ostream &OS,
|
| 142 |
+
const std::string &Banner) const = 0;
|
| 143 |
+
|
| 144 |
+
/// Each pass is responsible for assigning a pass manager to itself.
|
| 145 |
+
/// PMS is the stack of available pass manager.
|
| 146 |
+
virtual void assignPassManager(PMStack &,
|
| 147 |
+
PassManagerType) {}
|
| 148 |
+
|
| 149 |
+
/// Check if available pass managers are suitable for this pass or not.
|
| 150 |
+
virtual void preparePassManager(PMStack &);
|
| 151 |
+
|
| 152 |
+
/// Return what kind of Pass Manager can manage this pass.
|
| 153 |
+
virtual PassManagerType getPotentialPassManagerType() const;
|
| 154 |
+
|
| 155 |
+
// Access AnalysisResolver
|
| 156 |
+
void setResolver(AnalysisResolver *AR);
|
| 157 |
+
AnalysisResolver *getResolver() const { return Resolver; }
|
| 158 |
+
|
| 159 |
+
/// getAnalysisUsage - This function should be overriden by passes that need
|
| 160 |
+
/// analysis information to do their job. If a pass specifies that it uses a
|
| 161 |
+
/// particular analysis result to this function, it can then use the
|
| 162 |
+
/// getAnalysis<AnalysisType>() function, below.
|
| 163 |
+
virtual void getAnalysisUsage(AnalysisUsage &) const;
|
| 164 |
+
|
| 165 |
+
/// releaseMemory() - This member can be implemented by a pass if it wants to
|
| 166 |
+
/// be able to release its memory when it is no longer needed. The default
|
| 167 |
+
/// behavior of passes is to hold onto memory for the entire duration of their
|
| 168 |
+
/// lifetime (which is the entire compile time). For pipelined passes, this
|
| 169 |
+
/// is not a big deal because that memory gets recycled every time the pass is
|
| 170 |
+
/// invoked on another program unit. For IP passes, it is more important to
|
| 171 |
+
/// free memory when it is unused.
|
| 172 |
+
///
|
| 173 |
+
/// Optionally implement this function to release pass memory when it is no
|
| 174 |
+
/// longer used.
|
| 175 |
+
virtual void releaseMemory();
|
| 176 |
+
|
| 177 |
+
/// getAdjustedAnalysisPointer - This method is used when a pass implements
|
| 178 |
+
/// an analysis interface through multiple inheritance. If needed, it should
|
| 179 |
+
/// override this to adjust the this pointer as needed for the specified pass
|
| 180 |
+
/// info.
|
| 181 |
+
virtual void *getAdjustedAnalysisPointer(AnalysisID ID);
|
| 182 |
+
virtual ImmutablePass *getAsImmutablePass();
|
| 183 |
+
virtual PMDataManager *getAsPMDataManager();
|
| 184 |
+
|
| 185 |
+
/// verifyAnalysis() - This member can be implemented by a analysis pass to
|
| 186 |
+
/// check state of analysis information.
|
| 187 |
+
virtual void verifyAnalysis() const;
|
| 188 |
+
|
| 189 |
+
// dumpPassStructure - Implement the -debug-passes=PassStructure option
|
| 190 |
+
virtual void dumpPassStructure(unsigned Offset = 0);
|
| 191 |
+
|
| 192 |
+
// lookupPassInfo - Return the pass info object for the specified pass class,
|
| 193 |
+
// or null if it is not known.
|
| 194 |
+
static const PassInfo *lookupPassInfo(const void *TI);
|
| 195 |
+
|
| 196 |
+
// lookupPassInfo - Return the pass info object for the pass with the given
|
| 197 |
+
// argument string, or null if it is not known.
|
| 198 |
+
static const PassInfo *lookupPassInfo(StringRef Arg);
|
| 199 |
+
|
| 200 |
+
// createPass - Create a object for the specified pass class,
|
| 201 |
+
// or null if it is not known.
|
| 202 |
+
static Pass *createPass(AnalysisID ID);
|
| 203 |
+
|
| 204 |
+
/// getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to
|
| 205 |
+
/// get analysis information that might be around, for example to update it.
|
| 206 |
+
/// This is different than getAnalysis in that it can fail (if the analysis
|
| 207 |
+
/// results haven't been computed), so should only be used if you can handle
|
| 208 |
+
/// the case when the analysis is not available. This method is often used by
|
| 209 |
+
/// transformation APIs to update analysis results for a pass automatically as
|
| 210 |
+
/// the transform is performed.
|
| 211 |
+
template<typename AnalysisType> AnalysisType *
|
| 212 |
+
getAnalysisIfAvailable() const; // Defined in PassAnalysisSupport.h
|
| 213 |
+
|
| 214 |
+
/// mustPreserveAnalysisID - This method serves the same function as
|
| 215 |
+
/// getAnalysisIfAvailable, but works if you just have an AnalysisID. This
|
| 216 |
+
/// obviously cannot give you a properly typed instance of the class if you
|
| 217 |
+
/// don't have the class name available (use getAnalysisIfAvailable if you
|
| 218 |
+
/// do), but it can tell you if you need to preserve the pass at least.
|
| 219 |
+
bool mustPreserveAnalysisID(char &AID) const;
|
| 220 |
+
|
| 221 |
+
/// getAnalysis<AnalysisType>() - This function is used by subclasses to get
|
| 222 |
+
/// to the analysis information that they claim to use by overriding the
|
| 223 |
+
/// getAnalysisUsage function.
|
| 224 |
+
template<typename AnalysisType>
|
| 225 |
+
AnalysisType &getAnalysis() const; // Defined in PassAnalysisSupport.h
|
| 226 |
+
|
| 227 |
+
template <typename AnalysisType>
|
| 228 |
+
AnalysisType &
|
| 229 |
+
getAnalysis(Function &F,
|
| 230 |
+
bool *Changed = nullptr); // Defined in PassAnalysisSupport.h
|
| 231 |
+
|
| 232 |
+
template<typename AnalysisType>
|
| 233 |
+
AnalysisType &getAnalysisID(AnalysisID PI) const;
|
| 234 |
+
|
| 235 |
+
template <typename AnalysisType>
|
| 236 |
+
AnalysisType &getAnalysisID(AnalysisID PI, Function &F,
|
| 237 |
+
bool *Changed = nullptr);
|
| 238 |
+
|
| 239 |
+
#ifdef EXPENSIVE_CHECKS
|
| 240 |
+
/// Hash a module in order to detect when a module (or more specific) pass has
|
| 241 |
+
/// modified it.
|
| 242 |
+
uint64_t structuralHash(Module &M) const;
|
| 243 |
+
|
| 244 |
+
/// Hash a function in order to detect when a function (or more specific) pass
|
| 245 |
+
/// has modified it.
|
| 246 |
+
virtual uint64_t structuralHash(Function &F) const;
|
| 247 |
+
#endif
|
| 248 |
+
};
|
| 249 |
+
|
| 250 |
+
//===----------------------------------------------------------------------===//
|
| 251 |
+
/// ModulePass class - This class is used to implement unstructured
|
| 252 |
+
/// interprocedural optimizations and analyses. ModulePasses may do anything
|
| 253 |
+
/// they want to the program.
|
| 254 |
+
///
|
| 255 |
+
class ModulePass : public Pass {
|
| 256 |
+
public:
|
| 257 |
+
explicit ModulePass(char &pid) : Pass(PT_Module, pid) {}
|
| 258 |
+
|
| 259 |
+
// Force out-of-line virtual method.
|
| 260 |
+
~ModulePass() override;
|
| 261 |
+
|
| 262 |
+
/// createPrinterPass - Get a module printer pass.
|
| 263 |
+
Pass *createPrinterPass(raw_ostream &OS,
|
| 264 |
+
const std::string &Banner) const override;
|
| 265 |
+
|
| 266 |
+
/// runOnModule - Virtual method overriden by subclasses to process the module
|
| 267 |
+
/// being operated on.
|
| 268 |
+
virtual bool runOnModule(Module &M) = 0;
|
| 269 |
+
|
| 270 |
+
void assignPassManager(PMStack &PMS, PassManagerType T) override;
|
| 271 |
+
|
| 272 |
+
/// Return what kind of Pass Manager can manage this pass.
|
| 273 |
+
PassManagerType getPotentialPassManagerType() const override;
|
| 274 |
+
|
| 275 |
+
protected:
|
| 276 |
+
/// Optional passes call this function to check whether the pass should be
|
| 277 |
+
/// skipped. This is the case when optimization bisect is over the limit.
|
| 278 |
+
bool skipModule(Module &M) const;
|
| 279 |
+
};
|
| 280 |
+
|
| 281 |
+
//===----------------------------------------------------------------------===//
|
| 282 |
+
/// ImmutablePass class - This class is used to provide information that does
|
| 283 |
+
/// not need to be run. This is useful for things like target information.
|
| 284 |
+
///
|
| 285 |
+
class ImmutablePass : public ModulePass {
|
| 286 |
+
public:
|
| 287 |
+
explicit ImmutablePass(char &pid) : ModulePass(pid) {}
|
| 288 |
+
|
| 289 |
+
// Force out-of-line virtual method.
|
| 290 |
+
~ImmutablePass() override;
|
| 291 |
+
|
| 292 |
+
/// initializePass - This method may be overriden by immutable passes to allow
|
| 293 |
+
/// them to perform various initialization actions they require. This is
|
| 294 |
+
/// primarily because an ImmutablePass can "require" another ImmutablePass,
|
| 295 |
+
/// and if it does, the overloaded version of initializePass may get access to
|
| 296 |
+
/// these passes with getAnalysis<>.
|
| 297 |
+
virtual void initializePass();
|
| 298 |
+
|
| 299 |
+
ImmutablePass *getAsImmutablePass() override { return this; }
|
| 300 |
+
|
| 301 |
+
/// ImmutablePasses are never run.
|
| 302 |
+
bool runOnModule(Module &) override { return false; }
|
| 303 |
+
};
|
| 304 |
+
|
| 305 |
+
//===----------------------------------------------------------------------===//
|
| 306 |
+
/// FunctionPass class - This class is used to implement most global
|
| 307 |
+
/// optimizations. Optimizations should subclass this class if they meet the
|
| 308 |
+
/// following constraints:
|
| 309 |
+
///
|
| 310 |
+
/// 1. Optimizations are organized globally, i.e., a function at a time
|
| 311 |
+
/// 2. Optimizing a function does not cause the addition or removal of any
|
| 312 |
+
/// functions in the module
|
| 313 |
+
///
|
| 314 |
+
class FunctionPass : public Pass {
|
| 315 |
+
public:
|
| 316 |
+
explicit FunctionPass(char &pid) : Pass(PT_Function, pid) {}
|
| 317 |
+
|
| 318 |
+
/// createPrinterPass - Get a function printer pass.
|
| 319 |
+
Pass *createPrinterPass(raw_ostream &OS,
|
| 320 |
+
const std::string &Banner) const override;
|
| 321 |
+
|
| 322 |
+
/// runOnFunction - Virtual method overriden by subclasses to do the
|
| 323 |
+
/// per-function processing of the pass.
|
| 324 |
+
virtual bool runOnFunction(Function &F) = 0;
|
| 325 |
+
|
| 326 |
+
void assignPassManager(PMStack &PMS, PassManagerType T) override;
|
| 327 |
+
|
| 328 |
+
/// Return what kind of Pass Manager can manage this pass.
|
| 329 |
+
PassManagerType getPotentialPassManagerType() const override;
|
| 330 |
+
|
| 331 |
+
protected:
|
| 332 |
+
/// Optional passes call this function to check whether the pass should be
|
| 333 |
+
/// skipped. This is the case when Attribute::OptimizeNone is set or when
|
| 334 |
+
/// optimization bisect is over the limit.
|
| 335 |
+
bool skipFunction(const Function &F) const;
|
| 336 |
+
};
|
| 337 |
+
|
| 338 |
+
/// If the user specifies the -time-passes argument on an LLVM tool command line
|
| 339 |
+
/// then the value of this boolean will be true, otherwise false.
|
| 340 |
+
/// This is the storage for the -time-passes option.
|
| 341 |
+
extern bool TimePassesIsEnabled;
|
| 342 |
+
/// If TimePassesPerRun is true, there would be one line of report for
|
| 343 |
+
/// each pass invocation.
|
| 344 |
+
/// If TimePassesPerRun is false, there would be only one line of
|
| 345 |
+
/// report for each pass (even there are more than one pass objects).
|
| 346 |
+
/// (For new pass manager only)
|
| 347 |
+
extern bool TimePassesPerRun;
|
| 348 |
+
|
| 349 |
+
} // end namespace llvm
|
| 350 |
+
|
| 351 |
+
// Include support files that contain important APIs commonly used by Passes,
|
| 352 |
+
// but that we want to separate out to make it easier to read the header files.
|
| 353 |
+
#include "llvm/PassAnalysisSupport.h"
|
| 354 |
+
#include "llvm/PassSupport.h"
|
| 355 |
+
|
| 356 |
+
#endif // LLVM_PASS_H
|
deps/exla/cache/xla_extension/include/llvm/PassAnalysisSupport.h
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/PassAnalysisSupport.h - Analysis Pass Support code --*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines stuff that is used to define and "use" Analysis Passes.
|
| 10 |
+
// This file is automatically #included by Pass.h, so:
|
| 11 |
+
//
|
| 12 |
+
// NO .CPP FILES SHOULD INCLUDE THIS FILE DIRECTLY
|
| 13 |
+
//
|
| 14 |
+
// Instead, #include Pass.h
|
| 15 |
+
//
|
| 16 |
+
//===----------------------------------------------------------------------===//
|
| 17 |
+
|
| 18 |
+
#if !defined(LLVM_PASS_H) || defined(LLVM_PASSANALYSISSUPPORT_H)
|
| 19 |
+
#error "Do not include <PassAnalysisSupport.h>; include <Pass.h> instead"
|
| 20 |
+
#endif
|
| 21 |
+
|
| 22 |
+
#ifndef LLVM_PASSANALYSISSUPPORT_H
|
| 23 |
+
#define LLVM_PASSANALYSISSUPPORT_H
|
| 24 |
+
|
| 25 |
+
#include "llvm/ADT/STLExtras.h"
|
| 26 |
+
#include "llvm/ADT/SmallVector.h"
|
| 27 |
+
#include <cassert>
|
| 28 |
+
#include <tuple>
|
| 29 |
+
#include <utility>
|
| 30 |
+
#include <vector>
|
| 31 |
+
|
| 32 |
+
namespace llvm {
|
| 33 |
+
|
| 34 |
+
class Function;
|
| 35 |
+
class Pass;
|
| 36 |
+
class PMDataManager;
|
| 37 |
+
class StringRef;
|
| 38 |
+
|
| 39 |
+
//===----------------------------------------------------------------------===//
|
| 40 |
+
/// Represent the analysis usage information of a pass. This tracks analyses
|
| 41 |
+
/// that the pass REQUIRES (must be available when the pass runs), REQUIRES
|
| 42 |
+
/// TRANSITIVE (must be available throughout the lifetime of the pass), and
|
| 43 |
+
/// analyses that the pass PRESERVES (the pass does not invalidate the results
|
| 44 |
+
/// of these analyses). This information is provided by a pass to the Pass
|
| 45 |
+
/// infrastructure through the getAnalysisUsage virtual function.
|
| 46 |
+
///
|
| 47 |
+
class AnalysisUsage {
|
| 48 |
+
public:
|
| 49 |
+
using VectorType = SmallVectorImpl<AnalysisID>;
|
| 50 |
+
|
| 51 |
+
private:
|
| 52 |
+
/// Sets of analyses required and preserved by a pass
|
| 53 |
+
// TODO: It's not clear that SmallVector is an appropriate data structure for
|
| 54 |
+
// this usecase. The sizes were picked to minimize wasted space, but are
|
| 55 |
+
// otherwise fairly meaningless.
|
| 56 |
+
SmallVector<AnalysisID, 8> Required;
|
| 57 |
+
SmallVector<AnalysisID, 2> RequiredTransitive;
|
| 58 |
+
SmallVector<AnalysisID, 2> Preserved;
|
| 59 |
+
SmallVector<AnalysisID, 0> Used;
|
| 60 |
+
bool PreservesAll = false;
|
| 61 |
+
|
| 62 |
+
void pushUnique(VectorType &Set, AnalysisID ID) {
|
| 63 |
+
if (!llvm::is_contained(Set, ID))
|
| 64 |
+
Set.push_back(ID);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
public:
|
| 68 |
+
AnalysisUsage() = default;
|
| 69 |
+
|
| 70 |
+
///@{
|
| 71 |
+
/// Add the specified ID to the required set of the usage info for a pass.
|
| 72 |
+
AnalysisUsage &addRequiredID(const void *ID);
|
| 73 |
+
AnalysisUsage &addRequiredID(char &ID);
|
| 74 |
+
template<class PassClass>
|
| 75 |
+
AnalysisUsage &addRequired() {
|
| 76 |
+
return addRequiredID(PassClass::ID);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
AnalysisUsage &addRequiredTransitiveID(char &ID);
|
| 80 |
+
template<class PassClass>
|
| 81 |
+
AnalysisUsage &addRequiredTransitive() {
|
| 82 |
+
return addRequiredTransitiveID(PassClass::ID);
|
| 83 |
+
}
|
| 84 |
+
///@}
|
| 85 |
+
|
| 86 |
+
///@{
|
| 87 |
+
/// Add the specified ID to the set of analyses preserved by this pass.
|
| 88 |
+
AnalysisUsage &addPreservedID(const void *ID) {
|
| 89 |
+
pushUnique(Preserved, ID);
|
| 90 |
+
return *this;
|
| 91 |
+
}
|
| 92 |
+
AnalysisUsage &addPreservedID(char &ID) {
|
| 93 |
+
pushUnique(Preserved, &ID);
|
| 94 |
+
return *this;
|
| 95 |
+
}
|
| 96 |
+
/// Add the specified Pass class to the set of analyses preserved by this pass.
|
| 97 |
+
template<class PassClass>
|
| 98 |
+
AnalysisUsage &addPreserved() {
|
| 99 |
+
pushUnique(Preserved, &PassClass::ID);
|
| 100 |
+
return *this;
|
| 101 |
+
}
|
| 102 |
+
///@}
|
| 103 |
+
|
| 104 |
+
///@{
|
| 105 |
+
/// Add the specified ID to the set of analyses used by this pass if they are
|
| 106 |
+
/// available..
|
| 107 |
+
AnalysisUsage &addUsedIfAvailableID(const void *ID) {
|
| 108 |
+
pushUnique(Used, ID);
|
| 109 |
+
return *this;
|
| 110 |
+
}
|
| 111 |
+
AnalysisUsage &addUsedIfAvailableID(char &ID) {
|
| 112 |
+
pushUnique(Used, &ID);
|
| 113 |
+
return *this;
|
| 114 |
+
}
|
| 115 |
+
/// Add the specified Pass class to the set of analyses used by this pass.
|
| 116 |
+
template<class PassClass>
|
| 117 |
+
AnalysisUsage &addUsedIfAvailable() {
|
| 118 |
+
pushUnique(Used, &PassClass::ID);
|
| 119 |
+
return *this;
|
| 120 |
+
}
|
| 121 |
+
///@}
|
| 122 |
+
|
| 123 |
+
/// Add the Pass with the specified argument string to the set of analyses
|
| 124 |
+
/// preserved by this pass. If no such Pass exists, do nothing. This can be
|
| 125 |
+
/// useful when a pass is trivially preserved, but may not be linked in. Be
|
| 126 |
+
/// careful about spelling!
|
| 127 |
+
AnalysisUsage &addPreserved(StringRef Arg);
|
| 128 |
+
|
| 129 |
+
/// Set by analyses that do not transform their input at all
|
| 130 |
+
void setPreservesAll() { PreservesAll = true; }
|
| 131 |
+
|
| 132 |
+
/// Determine whether a pass said it does not transform its input at all
|
| 133 |
+
bool getPreservesAll() const { return PreservesAll; }
|
| 134 |
+
|
| 135 |
+
/// This function should be called by the pass, iff they do not:
|
| 136 |
+
///
|
| 137 |
+
/// 1. Add or remove basic blocks from the function
|
| 138 |
+
/// 2. Modify terminator instructions in any way.
|
| 139 |
+
///
|
| 140 |
+
/// This function annotates the AnalysisUsage info object to say that analyses
|
| 141 |
+
/// that only depend on the CFG are preserved by this pass.
|
| 142 |
+
void setPreservesCFG();
|
| 143 |
+
|
| 144 |
+
const VectorType &getRequiredSet() const { return Required; }
|
| 145 |
+
const VectorType &getRequiredTransitiveSet() const {
|
| 146 |
+
return RequiredTransitive;
|
| 147 |
+
}
|
| 148 |
+
const VectorType &getPreservedSet() const { return Preserved; }
|
| 149 |
+
const VectorType &getUsedSet() const { return Used; }
|
| 150 |
+
};
|
| 151 |
+
|
| 152 |
+
//===----------------------------------------------------------------------===//
|
| 153 |
+
/// AnalysisResolver - Simple interface used by Pass objects to pull all
|
| 154 |
+
/// analysis information out of pass manager that is responsible to manage
|
| 155 |
+
/// the pass.
|
| 156 |
+
///
|
| 157 |
+
class AnalysisResolver {
|
| 158 |
+
public:
|
| 159 |
+
AnalysisResolver() = delete;
|
| 160 |
+
explicit AnalysisResolver(PMDataManager &P) : PM(P) {}
|
| 161 |
+
|
| 162 |
+
PMDataManager &getPMDataManager() { return PM; }
|
| 163 |
+
|
| 164 |
+
/// Find pass that is implementing PI.
|
| 165 |
+
Pass *findImplPass(AnalysisID PI) {
|
| 166 |
+
Pass *ResultPass = nullptr;
|
| 167 |
+
for (const auto &AnalysisImpl : AnalysisImpls) {
|
| 168 |
+
if (AnalysisImpl.first == PI) {
|
| 169 |
+
ResultPass = AnalysisImpl.second;
|
| 170 |
+
break;
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
return ResultPass;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
/// Find pass that is implementing PI. Initialize pass for Function F.
|
| 177 |
+
std::tuple<Pass *, bool> findImplPass(Pass *P, AnalysisID PI, Function &F);
|
| 178 |
+
|
| 179 |
+
void addAnalysisImplsPair(AnalysisID PI, Pass *P) {
|
| 180 |
+
if (findImplPass(PI) == P)
|
| 181 |
+
return;
|
| 182 |
+
std::pair<AnalysisID, Pass*> pir = std::make_pair(PI,P);
|
| 183 |
+
AnalysisImpls.push_back(pir);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
/// Clear cache that is used to connect a pass to the analysis (PassInfo).
|
| 187 |
+
void clearAnalysisImpls() {
|
| 188 |
+
AnalysisImpls.clear();
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
/// Return analysis result or null if it doesn't exist.
|
| 192 |
+
Pass *getAnalysisIfAvailable(AnalysisID ID) const;
|
| 193 |
+
|
| 194 |
+
private:
|
| 195 |
+
/// This keeps track of which passes implements the interfaces that are
|
| 196 |
+
/// required by the current pass (to implement getAnalysis()).
|
| 197 |
+
std::vector<std::pair<AnalysisID, Pass *>> AnalysisImpls;
|
| 198 |
+
|
| 199 |
+
/// PassManager that is used to resolve analysis info
|
| 200 |
+
PMDataManager &PM;
|
| 201 |
+
};
|
| 202 |
+
|
| 203 |
+
/// getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to
|
| 204 |
+
/// get analysis information that might be around, for example to update it.
|
| 205 |
+
/// This is different than getAnalysis in that it can fail (if the analysis
|
| 206 |
+
/// results haven't been computed), so should only be used if you can handle
|
| 207 |
+
/// the case when the analysis is not available. This method is often used by
|
| 208 |
+
/// transformation APIs to update analysis results for a pass automatically as
|
| 209 |
+
/// the transform is performed.
|
| 210 |
+
template<typename AnalysisType>
|
| 211 |
+
AnalysisType *Pass::getAnalysisIfAvailable() const {
|
| 212 |
+
assert(Resolver && "Pass not resident in a PassManager object!");
|
| 213 |
+
|
| 214 |
+
const void *PI = &AnalysisType::ID;
|
| 215 |
+
|
| 216 |
+
Pass *ResultPass = Resolver->getAnalysisIfAvailable(PI);
|
| 217 |
+
if (!ResultPass) return nullptr;
|
| 218 |
+
|
| 219 |
+
// Because the AnalysisType may not be a subclass of pass (for
|
| 220 |
+
// AnalysisGroups), we use getAdjustedAnalysisPointer here to potentially
|
| 221 |
+
// adjust the return pointer (because the class may multiply inherit, once
|
| 222 |
+
// from pass, once from AnalysisType).
|
| 223 |
+
return (AnalysisType*)ResultPass->getAdjustedAnalysisPointer(PI);
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
/// getAnalysis<AnalysisType>() - This function is used by subclasses to get
|
| 227 |
+
/// to the analysis information that they claim to use by overriding the
|
| 228 |
+
/// getAnalysisUsage function.
|
| 229 |
+
template<typename AnalysisType>
|
| 230 |
+
AnalysisType &Pass::getAnalysis() const {
|
| 231 |
+
assert(Resolver && "Pass has not been inserted into a PassManager object!");
|
| 232 |
+
return getAnalysisID<AnalysisType>(&AnalysisType::ID);
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
template<typename AnalysisType>
|
| 236 |
+
AnalysisType &Pass::getAnalysisID(AnalysisID PI) const {
|
| 237 |
+
assert(PI && "getAnalysis for unregistered pass!");
|
| 238 |
+
assert(Resolver&&"Pass has not been inserted into a PassManager object!");
|
| 239 |
+
// PI *must* appear in AnalysisImpls. Because the number of passes used
|
| 240 |
+
// should be a small number, we just do a linear search over a (dense)
|
| 241 |
+
// vector.
|
| 242 |
+
Pass *ResultPass = Resolver->findImplPass(PI);
|
| 243 |
+
assert(ResultPass &&
|
| 244 |
+
"getAnalysis*() called on an analysis that was not "
|
| 245 |
+
"'required' by pass!");
|
| 246 |
+
|
| 247 |
+
// Because the AnalysisType may not be a subclass of pass (for
|
| 248 |
+
// AnalysisGroups), we use getAdjustedAnalysisPointer here to potentially
|
| 249 |
+
// adjust the return pointer (because the class may multiply inherit, once
|
| 250 |
+
// from pass, once from AnalysisType).
|
| 251 |
+
return *(AnalysisType*)ResultPass->getAdjustedAnalysisPointer(PI);
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
/// getAnalysis<AnalysisType>() - This function is used by subclasses to get
|
| 255 |
+
/// to the analysis information that they claim to use by overriding the
|
| 256 |
+
/// getAnalysisUsage function. If as part of the dependencies, an IR
|
| 257 |
+
/// transformation is triggered (e.g. because the analysis requires
|
| 258 |
+
/// BreakCriticalEdges), and Changed is non null, *Changed is updated.
|
| 259 |
+
template <typename AnalysisType>
|
| 260 |
+
AnalysisType &Pass::getAnalysis(Function &F, bool *Changed) {
|
| 261 |
+
assert(Resolver &&"Pass has not been inserted into a PassManager object!");
|
| 262 |
+
|
| 263 |
+
return getAnalysisID<AnalysisType>(&AnalysisType::ID, F, Changed);
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
template <typename AnalysisType>
|
| 267 |
+
AnalysisType &Pass::getAnalysisID(AnalysisID PI, Function &F, bool *Changed) {
|
| 268 |
+
assert(PI && "getAnalysis for unregistered pass!");
|
| 269 |
+
assert(Resolver && "Pass has not been inserted into a PassManager object!");
|
| 270 |
+
// PI *must* appear in AnalysisImpls. Because the number of passes used
|
| 271 |
+
// should be a small number, we just do a linear search over a (dense)
|
| 272 |
+
// vector.
|
| 273 |
+
Pass *ResultPass;
|
| 274 |
+
bool LocalChanged;
|
| 275 |
+
std::tie(ResultPass, LocalChanged) = Resolver->findImplPass(this, PI, F);
|
| 276 |
+
|
| 277 |
+
assert(ResultPass && "Unable to find requested analysis info");
|
| 278 |
+
if (Changed)
|
| 279 |
+
*Changed |= LocalChanged;
|
| 280 |
+
else
|
| 281 |
+
assert(!LocalChanged &&
|
| 282 |
+
"A pass trigged a code update but the update status is lost");
|
| 283 |
+
|
| 284 |
+
// Because the AnalysisType may not be a subclass of pass (for
|
| 285 |
+
// AnalysisGroups), we use getAdjustedAnalysisPointer here to potentially
|
| 286 |
+
// adjust the return pointer (because the class may multiply inherit, once
|
| 287 |
+
// from pass, once from AnalysisType).
|
| 288 |
+
return *(AnalysisType*)ResultPass->getAdjustedAnalysisPointer(PI);
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
} // end namespace llvm
|
| 292 |
+
|
| 293 |
+
#endif // LLVM_PASSANALYSISSUPPORT_H
|
deps/exla/cache/xla_extension/include/llvm/PassInfo.h
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/PassInfo.h - Pass Info class ------------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines and implements the PassInfo class.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_PASSINFO_H
|
| 14 |
+
#define LLVM_PASSINFO_H
|
| 15 |
+
|
| 16 |
+
#include "llvm/ADT/StringRef.h"
|
| 17 |
+
#include <cassert>
|
| 18 |
+
#include <vector>
|
| 19 |
+
|
| 20 |
+
namespace llvm {
|
| 21 |
+
|
| 22 |
+
class Pass;
|
| 23 |
+
|
| 24 |
+
//===---------------------------------------------------------------------------
|
| 25 |
+
/// PassInfo class - An instance of this class exists for every pass known by
|
| 26 |
+
/// the system, and can be obtained from a live Pass by calling its
|
| 27 |
+
/// getPassInfo() method. These objects are set up by the RegisterPass<>
|
| 28 |
+
/// template.
|
| 29 |
+
///
|
| 30 |
+
class PassInfo {
|
| 31 |
+
public:
|
| 32 |
+
using NormalCtor_t = Pass* (*)();
|
| 33 |
+
|
| 34 |
+
private:
|
| 35 |
+
StringRef PassName; // Nice name for Pass
|
| 36 |
+
StringRef PassArgument; // Command Line argument to run this pass
|
| 37 |
+
const void *PassID;
|
| 38 |
+
const bool IsCFGOnlyPass = false; // Pass only looks at the CFG.
|
| 39 |
+
const bool IsAnalysis; // True if an analysis pass.
|
| 40 |
+
NormalCtor_t NormalCtor = nullptr;
|
| 41 |
+
|
| 42 |
+
public:
|
| 43 |
+
/// PassInfo ctor - Do not call this directly, this should only be invoked
|
| 44 |
+
/// through RegisterPass.
|
| 45 |
+
PassInfo(StringRef name, StringRef arg, const void *pi, NormalCtor_t normal,
|
| 46 |
+
bool isCFGOnly, bool is_analysis)
|
| 47 |
+
: PassName(name), PassArgument(arg), PassID(pi), IsCFGOnlyPass(isCFGOnly),
|
| 48 |
+
IsAnalysis(is_analysis), NormalCtor(normal) {}
|
| 49 |
+
|
| 50 |
+
PassInfo(const PassInfo &) = delete;
|
| 51 |
+
PassInfo &operator=(const PassInfo &) = delete;
|
| 52 |
+
|
| 53 |
+
/// getPassName - Return the friendly name for the pass, never returns null
|
| 54 |
+
StringRef getPassName() const { return PassName; }
|
| 55 |
+
|
| 56 |
+
/// getPassArgument - Return the command line option that may be passed to
|
| 57 |
+
/// 'opt' that will cause this pass to be run. This will return null if there
|
| 58 |
+
/// is no argument.
|
| 59 |
+
StringRef getPassArgument() const { return PassArgument; }
|
| 60 |
+
|
| 61 |
+
/// getTypeInfo - Return the id object for the pass...
|
| 62 |
+
/// TODO : Rename
|
| 63 |
+
const void *getTypeInfo() const { return PassID; }
|
| 64 |
+
|
| 65 |
+
/// Return true if this PassID implements the specified ID pointer.
|
| 66 |
+
bool isPassID(const void *IDPtr) const { return PassID == IDPtr; }
|
| 67 |
+
|
| 68 |
+
bool isAnalysis() const { return IsAnalysis; }
|
| 69 |
+
|
| 70 |
+
/// isCFGOnlyPass - return true if this pass only looks at the CFG for the
|
| 71 |
+
/// function.
|
| 72 |
+
bool isCFGOnlyPass() const { return IsCFGOnlyPass; }
|
| 73 |
+
|
| 74 |
+
/// getNormalCtor - Return a pointer to a function, that when called, creates
|
| 75 |
+
/// an instance of the pass and returns it. This pointer may be null if there
|
| 76 |
+
/// is no default constructor for the pass.
|
| 77 |
+
NormalCtor_t getNormalCtor() const {
|
| 78 |
+
return NormalCtor;
|
| 79 |
+
}
|
| 80 |
+
void setNormalCtor(NormalCtor_t Ctor) {
|
| 81 |
+
NormalCtor = Ctor;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/// createPass() - Use this method to create an instance of this pass.
|
| 85 |
+
Pass *createPass() const {
|
| 86 |
+
assert(NormalCtor &&
|
| 87 |
+
"Cannot call createPass on PassInfo without default ctor!");
|
| 88 |
+
return NormalCtor();
|
| 89 |
+
}
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
} // end namespace llvm
|
| 93 |
+
|
| 94 |
+
#endif // LLVM_PASSINFO_H
|
deps/exla/cache/xla_extension/include/llvm/PassRegistry.h
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/PassRegistry.h - Pass Information Registry ----------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines PassRegistry, a class that is used in the initialization
|
| 10 |
+
// and registration of passes. At application startup, passes are registered
|
| 11 |
+
// with the PassRegistry, which is later provided to the PassManager for
|
| 12 |
+
// dependency resolution and similar tasks.
|
| 13 |
+
//
|
| 14 |
+
//===----------------------------------------------------------------------===//
|
| 15 |
+
|
| 16 |
+
#ifndef LLVM_PASSREGISTRY_H
|
| 17 |
+
#define LLVM_PASSREGISTRY_H
|
| 18 |
+
|
| 19 |
+
#include "llvm/ADT/DenseMap.h"
|
| 20 |
+
#include "llvm/ADT/StringMap.h"
|
| 21 |
+
#include "llvm/ADT/StringRef.h"
|
| 22 |
+
#include "llvm/Support/RWMutex.h"
|
| 23 |
+
#include <memory>
|
| 24 |
+
#include <vector>
|
| 25 |
+
|
| 26 |
+
namespace llvm {
|
| 27 |
+
|
| 28 |
+
class PassInfo;
|
| 29 |
+
struct PassRegistrationListener;
|
| 30 |
+
|
| 31 |
+
/// PassRegistry - This class manages the registration and intitialization of
|
| 32 |
+
/// the pass subsystem as application startup, and assists the PassManager
|
| 33 |
+
/// in resolving pass dependencies.
|
| 34 |
+
/// NOTE: PassRegistry is NOT thread-safe. If you want to use LLVM on multiple
|
| 35 |
+
/// threads simultaneously, you will need to use a separate PassRegistry on
|
| 36 |
+
/// each thread.
|
| 37 |
+
class PassRegistry {
|
| 38 |
+
mutable sys::SmartRWMutex<true> Lock;
|
| 39 |
+
|
| 40 |
+
/// PassInfoMap - Keep track of the PassInfo object for each registered pass.
|
| 41 |
+
using MapType = DenseMap<const void *, const PassInfo *>;
|
| 42 |
+
MapType PassInfoMap;
|
| 43 |
+
|
| 44 |
+
using StringMapType = StringMap<const PassInfo *>;
|
| 45 |
+
StringMapType PassInfoStringMap;
|
| 46 |
+
|
| 47 |
+
std::vector<std::unique_ptr<const PassInfo>> ToFree;
|
| 48 |
+
std::vector<PassRegistrationListener *> Listeners;
|
| 49 |
+
|
| 50 |
+
public:
|
| 51 |
+
PassRegistry() = default;
|
| 52 |
+
~PassRegistry();
|
| 53 |
+
|
| 54 |
+
/// getPassRegistry - Access the global registry object, which is
|
| 55 |
+
/// automatically initialized at application launch and destroyed by
|
| 56 |
+
/// llvm_shutdown.
|
| 57 |
+
static PassRegistry *getPassRegistry();
|
| 58 |
+
|
| 59 |
+
/// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
|
| 60 |
+
/// type identifier (&MyPass::ID).
|
| 61 |
+
const PassInfo *getPassInfo(const void *TI) const;
|
| 62 |
+
|
| 63 |
+
/// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
|
| 64 |
+
/// argument string.
|
| 65 |
+
const PassInfo *getPassInfo(StringRef Arg) const;
|
| 66 |
+
|
| 67 |
+
/// registerPass - Register a pass (by means of its PassInfo) with the
|
| 68 |
+
/// registry. Required in order to use the pass with a PassManager.
|
| 69 |
+
void registerPass(const PassInfo &PI, bool ShouldFree = false);
|
| 70 |
+
|
| 71 |
+
/// enumerateWith - Enumerate the registered passes, calling the provided
|
| 72 |
+
/// PassRegistrationListener's passEnumerate() callback on each of them.
|
| 73 |
+
void enumerateWith(PassRegistrationListener *L);
|
| 74 |
+
|
| 75 |
+
/// addRegistrationListener - Register the given PassRegistrationListener
|
| 76 |
+
/// to receive passRegistered() callbacks whenever a new pass is registered.
|
| 77 |
+
void addRegistrationListener(PassRegistrationListener *L);
|
| 78 |
+
|
| 79 |
+
/// removeRegistrationListener - Unregister a PassRegistrationListener so that
|
| 80 |
+
/// it no longer receives passRegistered() callbacks.
|
| 81 |
+
void removeRegistrationListener(PassRegistrationListener *L);
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
} // end namespace llvm
|
| 85 |
+
|
| 86 |
+
#endif // LLVM_PASSREGISTRY_H
|
deps/exla/cache/xla_extension/include/llvm/PassSupport.h
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/PassSupport.h - Pass Support code -------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines stuff that is used to define and "use" Passes. This file
|
| 10 |
+
// is automatically #included by Pass.h, so:
|
| 11 |
+
//
|
| 12 |
+
// NO .CPP FILES SHOULD INCLUDE THIS FILE DIRECTLY
|
| 13 |
+
//
|
| 14 |
+
// Instead, #include Pass.h.
|
| 15 |
+
//
|
| 16 |
+
// This file defines Pass registration code and classes used for it.
|
| 17 |
+
//
|
| 18 |
+
//===----------------------------------------------------------------------===//
|
| 19 |
+
|
| 20 |
+
#if !defined(LLVM_PASS_H) || defined(LLVM_PASSSUPPORT_H)
|
| 21 |
+
#error "Do not include <PassSupport.h>; include <Pass.h> instead"
|
| 22 |
+
#endif
|
| 23 |
+
|
| 24 |
+
#ifndef LLVM_PASSSUPPORT_H
|
| 25 |
+
#define LLVM_PASSSUPPORT_H
|
| 26 |
+
|
| 27 |
+
#include "llvm/ADT/StringRef.h"
|
| 28 |
+
#include "llvm/PassInfo.h"
|
| 29 |
+
#include "llvm/PassRegistry.h"
|
| 30 |
+
#include "llvm/Support/Error.h"
|
| 31 |
+
#include "llvm/Support/Threading.h"
|
| 32 |
+
#include <functional>
|
| 33 |
+
|
| 34 |
+
namespace llvm {
|
| 35 |
+
|
| 36 |
+
class Pass;
|
| 37 |
+
|
| 38 |
+
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis) \
|
| 39 |
+
static void initialize##passName##PassOnce(PassRegistry &Registry) {
|
| 40 |
+
|
| 41 |
+
#define INITIALIZE_PASS_DEPENDENCY(depName) initialize##depName##Pass(Registry);
|
| 42 |
+
|
| 43 |
+
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis) \
|
| 44 |
+
PassInfo *PI = new PassInfo( \
|
| 45 |
+
name, arg, &passName::ID, \
|
| 46 |
+
PassInfo::NormalCtor_t(callDefaultCtor<passName>), cfg, analysis); \
|
| 47 |
+
Registry.registerPass(*PI, true); \
|
| 48 |
+
} \
|
| 49 |
+
static llvm::once_flag Initialize##passName##PassFlag; \
|
| 50 |
+
void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
|
| 51 |
+
llvm::call_once(Initialize##passName##PassFlag, \
|
| 52 |
+
initialize##passName##PassOnce, std::ref(Registry)); \
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis) \
|
| 56 |
+
INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis) \
|
| 57 |
+
INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
|
| 58 |
+
|
| 59 |
+
#define INITIALIZE_PASS_WITH_OPTIONS_BEGIN(PassName, Arg, Name, Cfg, Analysis) \
|
| 60 |
+
INITIALIZE_PASS_BEGIN(PassName, Arg, Name, Cfg, Analysis) \
|
| 61 |
+
PassName::registerOptions();
|
| 62 |
+
|
| 63 |
+
#define INITIALIZE_PASS_WITH_OPTIONS(PassName, Arg, Name, Cfg, Analysis) \
|
| 64 |
+
INITIALIZE_PASS_WITH_OPTIONS_BEGIN(PassName, Arg, Name, Cfg, Analysis) \
|
| 65 |
+
INITIALIZE_PASS_END(PassName, Arg, Name, Cfg, Analysis)
|
| 66 |
+
|
| 67 |
+
template <class PassName> Pass *callDefaultCtor() {
|
| 68 |
+
if constexpr (std::is_default_constructible_v<PassName>)
|
| 69 |
+
return new PassName();
|
| 70 |
+
else
|
| 71 |
+
// Some codegen passes should only be testable via
|
| 72 |
+
// `llc -{start|stop}-{before|after}=<passname>`, not via `opt -<passname>`.
|
| 73 |
+
report_fatal_error("target-specific codegen-only pass");
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
//===---------------------------------------------------------------------------
|
| 77 |
+
/// RegisterPass<t> template - This template class is used to notify the system
|
| 78 |
+
/// that a Pass is available for use, and registers it into the internal
|
| 79 |
+
/// database maintained by the PassManager. Unless this template is used, opt,
|
| 80 |
+
/// for example will not be able to see the pass and attempts to create the pass
|
| 81 |
+
/// will fail. This template is used in the follow manner (at global scope, in
|
| 82 |
+
/// your .cpp file):
|
| 83 |
+
///
|
| 84 |
+
/// static RegisterPass<YourPassClassName> tmp("passopt", "My Pass Name");
|
| 85 |
+
///
|
| 86 |
+
/// This statement will cause your pass to be created by calling the default
|
| 87 |
+
/// constructor exposed by the pass.
|
| 88 |
+
template <typename passName> struct RegisterPass : public PassInfo {
|
| 89 |
+
// Register Pass using default constructor...
|
| 90 |
+
RegisterPass(StringRef PassArg, StringRef Name, bool CFGOnly = false,
|
| 91 |
+
bool is_analysis = false)
|
| 92 |
+
: PassInfo(Name, PassArg, &passName::ID,
|
| 93 |
+
PassInfo::NormalCtor_t(callDefaultCtor<passName>), CFGOnly,
|
| 94 |
+
is_analysis) {
|
| 95 |
+
PassRegistry::getPassRegistry()->registerPass(*this);
|
| 96 |
+
}
|
| 97 |
+
};
|
| 98 |
+
|
| 99 |
+
//===---------------------------------------------------------------------------
|
| 100 |
+
/// PassRegistrationListener class - This class is meant to be derived from by
|
| 101 |
+
/// clients that are interested in which passes get registered and unregistered
|
| 102 |
+
/// at runtime (which can be because of the RegisterPass constructors being run
|
| 103 |
+
/// as the program starts up, or may be because a shared object just got
|
| 104 |
+
/// loaded).
|
| 105 |
+
struct PassRegistrationListener {
|
| 106 |
+
PassRegistrationListener() = default;
|
| 107 |
+
virtual ~PassRegistrationListener() = default;
|
| 108 |
+
|
| 109 |
+
/// Callback functions - These functions are invoked whenever a pass is loaded
|
| 110 |
+
/// or removed from the current executable.
|
| 111 |
+
virtual void passRegistered(const PassInfo *) {}
|
| 112 |
+
|
| 113 |
+
/// enumeratePasses - Iterate over the registered passes, calling the
|
| 114 |
+
/// passEnumerate callback on each PassInfo object.
|
| 115 |
+
void enumeratePasses();
|
| 116 |
+
|
| 117 |
+
/// passEnumerate - Callback function invoked when someone calls
|
| 118 |
+
/// enumeratePasses on this PassRegistrationListener object.
|
| 119 |
+
virtual void passEnumerate(const PassInfo *) {}
|
| 120 |
+
};
|
| 121 |
+
|
| 122 |
+
} // end namespace llvm
|
| 123 |
+
|
| 124 |
+
#endif // LLVM_PASSSUPPORT_H
|
deps/exla/cache/xla_extension/include/llvm/Passes/CodeGenPassBuilder.h
ADDED
|
@@ -0,0 +1,1266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- Construction of codegen pass pipelines ------------------*- C++ -*--===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
/// \file
|
| 9 |
+
///
|
| 10 |
+
/// Interfaces for producing common pass manager configurations.
|
| 11 |
+
///
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#ifndef LLVM_PASSES_CODEGENPASSBUILDER_H
|
| 15 |
+
#define LLVM_PASSES_CODEGENPASSBUILDER_H
|
| 16 |
+
|
| 17 |
+
#include "llvm/ADT/SmallVector.h"
|
| 18 |
+
#include "llvm/ADT/StringRef.h"
|
| 19 |
+
#include "llvm/Analysis/AliasAnalysis.h"
|
| 20 |
+
#include "llvm/Analysis/BasicAliasAnalysis.h"
|
| 21 |
+
#include "llvm/Analysis/ProfileSummaryInfo.h"
|
| 22 |
+
#include "llvm/Analysis/ScopedNoAliasAA.h"
|
| 23 |
+
#include "llvm/Analysis/TargetTransformInfo.h"
|
| 24 |
+
#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
|
| 25 |
+
#include "llvm/CodeGen/AssignmentTrackingAnalysis.h"
|
| 26 |
+
#include "llvm/CodeGen/BranchFoldingPass.h"
|
| 27 |
+
#include "llvm/CodeGen/CallBrPrepare.h"
|
| 28 |
+
#include "llvm/CodeGen/CodeGenPrepare.h"
|
| 29 |
+
#include "llvm/CodeGen/DeadMachineInstructionElim.h"
|
| 30 |
+
#include "llvm/CodeGen/DetectDeadLanes.h"
|
| 31 |
+
#include "llvm/CodeGen/DwarfEHPrepare.h"
|
| 32 |
+
#include "llvm/CodeGen/EarlyIfConversion.h"
|
| 33 |
+
#include "llvm/CodeGen/ExpandFp.h"
|
| 34 |
+
#include "llvm/CodeGen/ExpandLargeDivRem.h"
|
| 35 |
+
#include "llvm/CodeGen/ExpandMemCmp.h"
|
| 36 |
+
#include "llvm/CodeGen/ExpandPostRAPseudos.h"
|
| 37 |
+
#include "llvm/CodeGen/ExpandReductions.h"
|
| 38 |
+
#include "llvm/CodeGen/FEntryInserter.h"
|
| 39 |
+
#include "llvm/CodeGen/FinalizeISel.h"
|
| 40 |
+
#include "llvm/CodeGen/FixupStatepointCallerSaved.h"
|
| 41 |
+
#include "llvm/CodeGen/GCMetadata.h"
|
| 42 |
+
#include "llvm/CodeGen/GlobalMerge.h"
|
| 43 |
+
#include "llvm/CodeGen/GlobalMergeFunctions.h"
|
| 44 |
+
#include "llvm/CodeGen/IndirectBrExpand.h"
|
| 45 |
+
#include "llvm/CodeGen/InterleavedAccess.h"
|
| 46 |
+
#include "llvm/CodeGen/InterleavedLoadCombine.h"
|
| 47 |
+
#include "llvm/CodeGen/JMCInstrumenter.h"
|
| 48 |
+
#include "llvm/CodeGen/LiveDebugValuesPass.h"
|
| 49 |
+
#include "llvm/CodeGen/LiveIntervals.h"
|
| 50 |
+
#include "llvm/CodeGen/LiveVariables.h"
|
| 51 |
+
#include "llvm/CodeGen/LocalStackSlotAllocation.h"
|
| 52 |
+
#include "llvm/CodeGen/LowerEmuTLS.h"
|
| 53 |
+
#include "llvm/CodeGen/MIRPrinter.h"
|
| 54 |
+
#include "llvm/CodeGen/MachineBlockPlacement.h"
|
| 55 |
+
#include "llvm/CodeGen/MachineCSE.h"
|
| 56 |
+
#include "llvm/CodeGen/MachineCopyPropagation.h"
|
| 57 |
+
#include "llvm/CodeGen/MachineFunctionAnalysis.h"
|
| 58 |
+
#include "llvm/CodeGen/MachineLICM.h"
|
| 59 |
+
#include "llvm/CodeGen/MachineLateInstrsCleanup.h"
|
| 60 |
+
#include "llvm/CodeGen/MachineModuleInfo.h"
|
| 61 |
+
#include "llvm/CodeGen/MachinePassManager.h"
|
| 62 |
+
#include "llvm/CodeGen/MachineScheduler.h"
|
| 63 |
+
#include "llvm/CodeGen/MachineSink.h"
|
| 64 |
+
#include "llvm/CodeGen/MachineVerifier.h"
|
| 65 |
+
#include "llvm/CodeGen/OptimizePHIs.h"
|
| 66 |
+
#include "llvm/CodeGen/PEI.h"
|
| 67 |
+
#include "llvm/CodeGen/PHIElimination.h"
|
| 68 |
+
#include "llvm/CodeGen/PatchableFunction.h"
|
| 69 |
+
#include "llvm/CodeGen/PeepholeOptimizer.h"
|
| 70 |
+
#include "llvm/CodeGen/PostRASchedulerList.h"
|
| 71 |
+
#include "llvm/CodeGen/PreISelIntrinsicLowering.h"
|
| 72 |
+
#include "llvm/CodeGen/RegAllocEvictionAdvisor.h"
|
| 73 |
+
#include "llvm/CodeGen/RegAllocFast.h"
|
| 74 |
+
#include "llvm/CodeGen/RegAllocGreedyPass.h"
|
| 75 |
+
#include "llvm/CodeGen/RegUsageInfoCollector.h"
|
| 76 |
+
#include "llvm/CodeGen/RegUsageInfoPropagate.h"
|
| 77 |
+
#include "llvm/CodeGen/RegisterCoalescerPass.h"
|
| 78 |
+
#include "llvm/CodeGen/RegisterUsageInfo.h"
|
| 79 |
+
#include "llvm/CodeGen/RemoveLoadsIntoFakeUses.h"
|
| 80 |
+
#include "llvm/CodeGen/RemoveRedundantDebugValues.h"
|
| 81 |
+
#include "llvm/CodeGen/RenameIndependentSubregs.h"
|
| 82 |
+
#include "llvm/CodeGen/ReplaceWithVeclib.h"
|
| 83 |
+
#include "llvm/CodeGen/SafeStack.h"
|
| 84 |
+
#include "llvm/CodeGen/SanitizerBinaryMetadata.h"
|
| 85 |
+
#include "llvm/CodeGen/SelectOptimize.h"
|
| 86 |
+
#include "llvm/CodeGen/ShadowStackGCLowering.h"
|
| 87 |
+
#include "llvm/CodeGen/ShrinkWrap.h"
|
| 88 |
+
#include "llvm/CodeGen/SjLjEHPrepare.h"
|
| 89 |
+
#include "llvm/CodeGen/StackColoring.h"
|
| 90 |
+
#include "llvm/CodeGen/StackFrameLayoutAnalysisPass.h"
|
| 91 |
+
#include "llvm/CodeGen/StackProtector.h"
|
| 92 |
+
#include "llvm/CodeGen/StackSlotColoring.h"
|
| 93 |
+
#include "llvm/CodeGen/TailDuplication.h"
|
| 94 |
+
#include "llvm/CodeGen/TargetPassConfig.h"
|
| 95 |
+
#include "llvm/CodeGen/TwoAddressInstructionPass.h"
|
| 96 |
+
#include "llvm/CodeGen/UnreachableBlockElim.h"
|
| 97 |
+
#include "llvm/CodeGen/VirtRegMap.h"
|
| 98 |
+
#include "llvm/CodeGen/WasmEHPrepare.h"
|
| 99 |
+
#include "llvm/CodeGen/WinEHPrepare.h"
|
| 100 |
+
#include "llvm/CodeGen/XRayInstrumentation.h"
|
| 101 |
+
#include "llvm/IR/PassManager.h"
|
| 102 |
+
#include "llvm/IR/Verifier.h"
|
| 103 |
+
#include "llvm/IRPrinter/IRPrintingPasses.h"
|
| 104 |
+
#include "llvm/MC/MCAsmInfo.h"
|
| 105 |
+
#include "llvm/MC/MCTargetOptions.h"
|
| 106 |
+
#include "llvm/Support/CodeGen.h"
|
| 107 |
+
#include "llvm/Support/Debug.h"
|
| 108 |
+
#include "llvm/Support/Error.h"
|
| 109 |
+
#include "llvm/Support/ErrorHandling.h"
|
| 110 |
+
#include "llvm/Target/CGPassBuilderOption.h"
|
| 111 |
+
#include "llvm/Target/TargetMachine.h"
|
| 112 |
+
#include "llvm/Transforms/CFGuard.h"
|
| 113 |
+
#include "llvm/Transforms/Scalar/ConstantHoisting.h"
|
| 114 |
+
#include "llvm/Transforms/Scalar/LoopPassManager.h"
|
| 115 |
+
#include "llvm/Transforms/Scalar/LoopStrengthReduce.h"
|
| 116 |
+
#include "llvm/Transforms/Scalar/LowerConstantIntrinsics.h"
|
| 117 |
+
#include "llvm/Transforms/Scalar/MergeICmps.h"
|
| 118 |
+
#include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
|
| 119 |
+
#include "llvm/Transforms/Scalar/ScalarizeMaskedMemIntrin.h"
|
| 120 |
+
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
|
| 121 |
+
#include "llvm/Transforms/Utils/LowerInvoke.h"
|
| 122 |
+
#include <cassert>
|
| 123 |
+
#include <type_traits>
|
| 124 |
+
#include <utility>
|
| 125 |
+
|
| 126 |
+
namespace llvm {
|
| 127 |
+
|
| 128 |
+
// FIXME: Dummy target independent passes definitions that have not yet been
|
| 129 |
+
// ported to new pass manager. Once they do, remove these.
|
| 130 |
+
#define DUMMY_FUNCTION_PASS(NAME, PASS_NAME) \
|
| 131 |
+
struct PASS_NAME : public PassInfoMixin<PASS_NAME> { \
|
| 132 |
+
template <typename... Ts> PASS_NAME(Ts &&...) {} \
|
| 133 |
+
PreservedAnalyses run(Function &, FunctionAnalysisManager &) { \
|
| 134 |
+
return PreservedAnalyses::all(); \
|
| 135 |
+
} \
|
| 136 |
+
};
|
| 137 |
+
#define DUMMY_MACHINE_MODULE_PASS(NAME, PASS_NAME) \
|
| 138 |
+
struct PASS_NAME : public PassInfoMixin<PASS_NAME> { \
|
| 139 |
+
template <typename... Ts> PASS_NAME(Ts &&...) {} \
|
| 140 |
+
PreservedAnalyses run(Module &, ModuleAnalysisManager &) { \
|
| 141 |
+
return PreservedAnalyses::all(); \
|
| 142 |
+
} \
|
| 143 |
+
};
|
| 144 |
+
#define DUMMY_MACHINE_FUNCTION_PASS(NAME, PASS_NAME) \
|
| 145 |
+
struct PASS_NAME : public PassInfoMixin<PASS_NAME> { \
|
| 146 |
+
template <typename... Ts> PASS_NAME(Ts &&...) {} \
|
| 147 |
+
PreservedAnalyses run(MachineFunction &, \
|
| 148 |
+
MachineFunctionAnalysisManager &) { \
|
| 149 |
+
return PreservedAnalyses::all(); \
|
| 150 |
+
} \
|
| 151 |
+
};
|
| 152 |
+
#include "llvm/Passes/MachinePassRegistry.def"
|
| 153 |
+
|
| 154 |
+
/// This class provides access to building LLVM's passes.
|
| 155 |
+
///
|
| 156 |
+
/// Its members provide the baseline state available to passes during their
|
| 157 |
+
/// construction. The \c MachinePassRegistry.def file specifies how to construct
|
| 158 |
+
/// all of the built-in passes, and those may reference these members during
|
| 159 |
+
/// construction.
|
| 160 |
+
template <typename DerivedT, typename TargetMachineT> class CodeGenPassBuilder {
|
| 161 |
+
public:
|
| 162 |
+
explicit CodeGenPassBuilder(TargetMachineT &TM,
|
| 163 |
+
const CGPassBuilderOption &Opts,
|
| 164 |
+
PassInstrumentationCallbacks *PIC)
|
| 165 |
+
: TM(TM), Opt(Opts), PIC(PIC) {
|
| 166 |
+
// Target could set CGPassBuilderOption::MISchedPostRA to true to achieve
|
| 167 |
+
// substitutePass(&PostRASchedulerID, &PostMachineSchedulerID)
|
| 168 |
+
|
| 169 |
+
// Target should override TM.Options.EnableIPRA in their target-specific
|
| 170 |
+
// LLVMTM ctor. See TargetMachine::setGlobalISel for example.
|
| 171 |
+
if (Opt.EnableIPRA)
|
| 172 |
+
TM.Options.EnableIPRA = *Opt.EnableIPRA;
|
| 173 |
+
|
| 174 |
+
if (Opt.EnableGlobalISelAbort)
|
| 175 |
+
TM.Options.GlobalISelAbort = *Opt.EnableGlobalISelAbort;
|
| 176 |
+
|
| 177 |
+
if (!Opt.OptimizeRegAlloc)
|
| 178 |
+
Opt.OptimizeRegAlloc = getOptLevel() != CodeGenOptLevel::None;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
Error buildPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out,
|
| 182 |
+
raw_pwrite_stream *DwoOut,
|
| 183 |
+
CodeGenFileType FileType) const;
|
| 184 |
+
|
| 185 |
+
PassInstrumentationCallbacks *getPassInstrumentationCallbacks() const {
|
| 186 |
+
return PIC;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
protected:
|
| 190 |
+
template <typename PassT>
|
| 191 |
+
using has_required_t = decltype(std::declval<PassT &>().isRequired());
|
| 192 |
+
|
| 193 |
+
template <typename PassT>
|
| 194 |
+
using is_module_pass_t = decltype(std::declval<PassT &>().run(
|
| 195 |
+
std::declval<Module &>(), std::declval<ModuleAnalysisManager &>()));
|
| 196 |
+
|
| 197 |
+
template <typename PassT>
|
| 198 |
+
using is_function_pass_t = decltype(std::declval<PassT &>().run(
|
| 199 |
+
std::declval<Function &>(), std::declval<FunctionAnalysisManager &>()));
|
| 200 |
+
|
| 201 |
+
template <typename PassT>
|
| 202 |
+
using is_machine_function_pass_t = decltype(std::declval<PassT &>().run(
|
| 203 |
+
std::declval<MachineFunction &>(),
|
| 204 |
+
std::declval<MachineFunctionAnalysisManager &>()));
|
| 205 |
+
|
| 206 |
+
// Function object to maintain state while adding codegen IR passes.
|
| 207 |
+
// TODO: add a Function -> MachineFunction adaptor and merge
|
| 208 |
+
// AddIRPass/AddMachinePass so we can have a function pipeline that runs both
|
| 209 |
+
// function passes and machine function passes.
|
| 210 |
+
class AddIRPass {
|
| 211 |
+
public:
|
| 212 |
+
AddIRPass(ModulePassManager &MPM, const DerivedT &PB) : MPM(MPM), PB(PB) {}
|
| 213 |
+
~AddIRPass() {
|
| 214 |
+
if (!FPM.isEmpty())
|
| 215 |
+
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
template <typename PassT>
|
| 219 |
+
void operator()(PassT &&Pass, StringRef Name = PassT::name()) {
|
| 220 |
+
static_assert((is_detected<is_function_pass_t, PassT>::value ||
|
| 221 |
+
is_detected<is_module_pass_t, PassT>::value) &&
|
| 222 |
+
"Only module pass and function pass are supported.");
|
| 223 |
+
bool Required = false;
|
| 224 |
+
if constexpr (is_detected<has_required_t, PassT>::value)
|
| 225 |
+
Required = PassT::isRequired();
|
| 226 |
+
if (!PB.runBeforeAdding(Name) && !Required)
|
| 227 |
+
return;
|
| 228 |
+
|
| 229 |
+
// Add Function Pass
|
| 230 |
+
if constexpr (is_detected<is_function_pass_t, PassT>::value) {
|
| 231 |
+
FPM.addPass(std::forward<PassT>(Pass));
|
| 232 |
+
} else {
|
| 233 |
+
// Add Module Pass
|
| 234 |
+
if (!FPM.isEmpty()) {
|
| 235 |
+
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
|
| 236 |
+
FPM = FunctionPassManager();
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
MPM.addPass(std::forward<PassT>(Pass));
|
| 240 |
+
}
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
private:
|
| 244 |
+
ModulePassManager &MPM;
|
| 245 |
+
FunctionPassManager FPM;
|
| 246 |
+
const DerivedT &PB;
|
| 247 |
+
};
|
| 248 |
+
|
| 249 |
+
// Function object to maintain state while adding codegen machine passes.
|
| 250 |
+
class AddMachinePass {
|
| 251 |
+
public:
|
| 252 |
+
AddMachinePass(ModulePassManager &MPM, const DerivedT &PB)
|
| 253 |
+
: MPM(MPM), PB(PB) {}
|
| 254 |
+
~AddMachinePass() {
|
| 255 |
+
if (!MFPM.isEmpty()) {
|
| 256 |
+
FunctionPassManager FPM;
|
| 257 |
+
FPM.addPass(
|
| 258 |
+
createFunctionToMachineFunctionPassAdaptor(std::move(MFPM)));
|
| 259 |
+
FPM.addPass(InvalidateAnalysisPass<MachineFunctionAnalysis>());
|
| 260 |
+
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
|
| 261 |
+
}
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
template <typename PassT>
|
| 265 |
+
void operator()(PassT &&Pass, bool Force = false,
|
| 266 |
+
StringRef Name = PassT::name()) {
|
| 267 |
+
static_assert((is_detected<is_machine_function_pass_t, PassT>::value ||
|
| 268 |
+
is_detected<is_module_pass_t, PassT>::value) &&
|
| 269 |
+
"Only module pass and function pass are supported.");
|
| 270 |
+
|
| 271 |
+
if (!Force && !PB.runBeforeAdding(Name))
|
| 272 |
+
return;
|
| 273 |
+
|
| 274 |
+
// Add Function Pass
|
| 275 |
+
if constexpr (is_detected<is_machine_function_pass_t, PassT>::value) {
|
| 276 |
+
MFPM.addPass(std::forward<PassT>(Pass));
|
| 277 |
+
} else {
|
| 278 |
+
// Add Module Pass
|
| 279 |
+
if (!MFPM.isEmpty()) {
|
| 280 |
+
MPM.addPass(createModuleToFunctionPassAdaptor(
|
| 281 |
+
createFunctionToMachineFunctionPassAdaptor(std::move(MFPM))));
|
| 282 |
+
MFPM = MachineFunctionPassManager();
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
MPM.addPass(std::forward<PassT>(Pass));
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
for (auto &C : PB.AfterCallbacks)
|
| 289 |
+
C(Name, MFPM);
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
private:
|
| 293 |
+
ModulePassManager &MPM;
|
| 294 |
+
MachineFunctionPassManager MFPM;
|
| 295 |
+
const DerivedT &PB;
|
| 296 |
+
};
|
| 297 |
+
|
| 298 |
+
TargetMachineT &TM;
|
| 299 |
+
CGPassBuilderOption Opt;
|
| 300 |
+
PassInstrumentationCallbacks *PIC;
|
| 301 |
+
|
| 302 |
+
template <typename TMC> TMC &getTM() const { return static_cast<TMC &>(TM); }
|
| 303 |
+
CodeGenOptLevel getOptLevel() const { return TM.getOptLevel(); }
|
| 304 |
+
|
| 305 |
+
/// Check whether or not GlobalISel should abort on error.
|
| 306 |
+
/// When this is disabled, GlobalISel will fall back on SDISel instead of
|
| 307 |
+
/// erroring out.
|
| 308 |
+
bool isGlobalISelAbortEnabled() const {
|
| 309 |
+
return TM.Options.GlobalISelAbort == GlobalISelAbortMode::Enable;
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
/// Check whether or not a diagnostic should be emitted when GlobalISel
|
| 313 |
+
/// uses the fallback path. In other words, it will emit a diagnostic
|
| 314 |
+
/// when GlobalISel failed and isGlobalISelAbortEnabled is false.
|
| 315 |
+
bool reportDiagnosticWhenGlobalISelFallback() const {
|
| 316 |
+
return TM.Options.GlobalISelAbort == GlobalISelAbortMode::DisableWithDiag;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
/// addInstSelector - This method should install an instruction selector pass,
|
| 320 |
+
/// which converts from LLVM code to machine instructions.
|
| 321 |
+
Error addInstSelector(AddMachinePass &) const {
|
| 322 |
+
return make_error<StringError>("addInstSelector is not overridden",
|
| 323 |
+
inconvertibleErrorCode());
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
/// Target can override this to add GlobalMergePass before all IR passes.
|
| 327 |
+
void addGlobalMergePass(AddIRPass &) const {}
|
| 328 |
+
|
| 329 |
+
/// Add passes that optimize instruction level parallelism for out-of-order
|
| 330 |
+
/// targets. These passes are run while the machine code is still in SSA
|
| 331 |
+
/// form, so they can use MachineTraceMetrics to control their heuristics.
|
| 332 |
+
///
|
| 333 |
+
/// All passes added here should preserve the MachineDominatorTree,
|
| 334 |
+
/// MachineLoopInfo, and MachineTraceMetrics analyses.
|
| 335 |
+
void addILPOpts(AddMachinePass &) const {}
|
| 336 |
+
|
| 337 |
+
/// This method may be implemented by targets that want to run passes
|
| 338 |
+
/// immediately before register allocation.
|
| 339 |
+
void addPreRegAlloc(AddMachinePass &) const {}
|
| 340 |
+
|
| 341 |
+
/// addPreRewrite - Add passes to the optimized register allocation pipeline
|
| 342 |
+
/// after register allocation is complete, but before virtual registers are
|
| 343 |
+
/// rewritten to physical registers.
|
| 344 |
+
///
|
| 345 |
+
/// These passes must preserve VirtRegMap and LiveIntervals, and when running
|
| 346 |
+
/// after RABasic or RAGreedy, they should take advantage of LiveRegMatrix.
|
| 347 |
+
/// When these passes run, VirtRegMap contains legal physreg assignments for
|
| 348 |
+
/// all virtual registers.
|
| 349 |
+
///
|
| 350 |
+
/// Note if the target overloads addRegAssignAndRewriteOptimized, this may not
|
| 351 |
+
/// be honored. This is also not generally used for the fast variant,
|
| 352 |
+
/// where the allocation and rewriting are done in one pass.
|
| 353 |
+
void addPreRewrite(AddMachinePass &) const {}
|
| 354 |
+
|
| 355 |
+
/// Add passes to be run immediately after virtual registers are rewritten
|
| 356 |
+
/// to physical registers.
|
| 357 |
+
void addPostRewrite(AddMachinePass &) const {}
|
| 358 |
+
|
| 359 |
+
/// This method may be implemented by targets that want to run passes after
|
| 360 |
+
/// register allocation pass pipeline but before prolog-epilog insertion.
|
| 361 |
+
void addPostRegAlloc(AddMachinePass &) const {}
|
| 362 |
+
|
| 363 |
+
/// This method may be implemented by targets that want to run passes after
|
| 364 |
+
/// prolog-epilog insertion and before the second instruction scheduling pass.
|
| 365 |
+
void addPreSched2(AddMachinePass &) const {}
|
| 366 |
+
|
| 367 |
+
/// This pass may be implemented by targets that want to run passes
|
| 368 |
+
/// immediately before machine code is emitted.
|
| 369 |
+
void addPreEmitPass(AddMachinePass &) const {}
|
| 370 |
+
|
| 371 |
+
/// Targets may add passes immediately before machine code is emitted in this
|
| 372 |
+
/// callback. This is called even later than `addPreEmitPass`.
|
| 373 |
+
// FIXME: Rename `addPreEmitPass` to something more sensible given its actual
|
| 374 |
+
// position and remove the `2` suffix here as this callback is what
|
| 375 |
+
// `addPreEmitPass` *should* be but in reality isn't.
|
| 376 |
+
void addPreEmitPass2(AddMachinePass &) const {}
|
| 377 |
+
|
| 378 |
+
/// {{@ For GlobalISel
|
| 379 |
+
///
|
| 380 |
+
|
| 381 |
+
/// addPreISel - This method should add any "last minute" LLVM->LLVM
|
| 382 |
+
/// passes (which are run just before instruction selector).
|
| 383 |
+
void addPreISel(AddIRPass &) const {
|
| 384 |
+
llvm_unreachable("addPreISel is not overridden");
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
/// This method should install an IR translator pass, which converts from
|
| 388 |
+
/// LLVM code to machine instructions with possibly generic opcodes.
|
| 389 |
+
Error addIRTranslator(AddMachinePass &) const {
|
| 390 |
+
return make_error<StringError>("addIRTranslator is not overridden",
|
| 391 |
+
inconvertibleErrorCode());
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
/// This method may be implemented by targets that want to run passes
|
| 395 |
+
/// immediately before legalization.
|
| 396 |
+
void addPreLegalizeMachineIR(AddMachinePass &) const {}
|
| 397 |
+
|
| 398 |
+
/// This method should install a legalize pass, which converts the instruction
|
| 399 |
+
/// sequence into one that can be selected by the target.
|
| 400 |
+
Error addLegalizeMachineIR(AddMachinePass &) const {
|
| 401 |
+
return make_error<StringError>("addLegalizeMachineIR is not overridden",
|
| 402 |
+
inconvertibleErrorCode());
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
/// This method may be implemented by targets that want to run passes
|
| 406 |
+
/// immediately before the register bank selection.
|
| 407 |
+
void addPreRegBankSelect(AddMachinePass &) const {}
|
| 408 |
+
|
| 409 |
+
/// This method should install a register bank selector pass, which
|
| 410 |
+
/// assigns register banks to virtual registers without a register
|
| 411 |
+
/// class or register banks.
|
| 412 |
+
Error addRegBankSelect(AddMachinePass &) const {
|
| 413 |
+
return make_error<StringError>("addRegBankSelect is not overridden",
|
| 414 |
+
inconvertibleErrorCode());
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
/// This method may be implemented by targets that want to run passes
|
| 418 |
+
/// immediately before the (global) instruction selection.
|
| 419 |
+
void addPreGlobalInstructionSelect(AddMachinePass &) const {}
|
| 420 |
+
|
| 421 |
+
/// This method should install a (global) instruction selector pass, which
|
| 422 |
+
/// converts possibly generic instructions to fully target-specific
|
| 423 |
+
/// instructions, thereby constraining all generic virtual registers to
|
| 424 |
+
/// register classes.
|
| 425 |
+
Error addGlobalInstructionSelect(AddMachinePass &) const {
|
| 426 |
+
return make_error<StringError>(
|
| 427 |
+
"addGlobalInstructionSelect is not overridden",
|
| 428 |
+
inconvertibleErrorCode());
|
| 429 |
+
}
|
| 430 |
+
/// @}}
|
| 431 |
+
|
| 432 |
+
/// High level function that adds all passes necessary to go from llvm IR
|
| 433 |
+
/// representation to the MI representation.
|
| 434 |
+
/// Adds IR based lowering and target specific optimization passes and finally
|
| 435 |
+
/// the core instruction selection passes.
|
| 436 |
+
void addISelPasses(AddIRPass &) const;
|
| 437 |
+
|
| 438 |
+
/// Add the actual instruction selection passes. This does not include
|
| 439 |
+
/// preparation passes on IR.
|
| 440 |
+
Error addCoreISelPasses(AddMachinePass &) const;
|
| 441 |
+
|
| 442 |
+
/// Add the complete, standard set of LLVM CodeGen passes.
|
| 443 |
+
/// Fully developed targets will not generally override this.
|
| 444 |
+
Error addMachinePasses(AddMachinePass &) const;
|
| 445 |
+
|
| 446 |
+
/// Add passes to lower exception handling for the code generator.
|
| 447 |
+
void addPassesToHandleExceptions(AddIRPass &) const;
|
| 448 |
+
|
| 449 |
+
/// Add common target configurable passes that perform LLVM IR to IR
|
| 450 |
+
/// transforms following machine independent optimization.
|
| 451 |
+
void addIRPasses(AddIRPass &) const;
|
| 452 |
+
|
| 453 |
+
/// Add pass to prepare the LLVM IR for code generation. This should be done
|
| 454 |
+
/// before exception handling preparation passes.
|
| 455 |
+
void addCodeGenPrepare(AddIRPass &) const;
|
| 456 |
+
|
| 457 |
+
/// Add common passes that perform LLVM IR to IR transforms in preparation for
|
| 458 |
+
/// instruction selection.
|
| 459 |
+
void addISelPrepare(AddIRPass &) const;
|
| 460 |
+
|
| 461 |
+
/// Methods with trivial inline returns are convenient points in the common
|
| 462 |
+
/// codegen pass pipeline where targets may insert passes. Methods with
|
| 463 |
+
/// out-of-line standard implementations are major CodeGen stages called by
|
| 464 |
+
/// addMachinePasses. Some targets may override major stages when inserting
|
| 465 |
+
/// passes is insufficient, but maintaining overriden stages is more work.
|
| 466 |
+
///
|
| 467 |
+
|
| 468 |
+
/// addMachineSSAOptimization - Add standard passes that optimize machine
|
| 469 |
+
/// instructions in SSA form.
|
| 470 |
+
void addMachineSSAOptimization(AddMachinePass &) const;
|
| 471 |
+
|
| 472 |
+
/// addFastRegAlloc - Add the minimum set of target-independent passes that
|
| 473 |
+
/// are required for fast register allocation.
|
| 474 |
+
Error addFastRegAlloc(AddMachinePass &) const;
|
| 475 |
+
|
| 476 |
+
/// addOptimizedRegAlloc - Add passes related to register allocation.
|
| 477 |
+
/// CodeGenTargetMachineImpl provides standard regalloc passes for most
|
| 478 |
+
/// targets.
|
| 479 |
+
void addOptimizedRegAlloc(AddMachinePass &) const;
|
| 480 |
+
|
| 481 |
+
/// Add passes that optimize machine instructions after register allocation.
|
| 482 |
+
void addMachineLateOptimization(AddMachinePass &) const;
|
| 483 |
+
|
| 484 |
+
/// addGCPasses - Add late codegen passes that analyze code for garbage
|
| 485 |
+
/// collection. This should return true if GC info should be printed after
|
| 486 |
+
/// these passes.
|
| 487 |
+
void addGCPasses(AddMachinePass &) const {}
|
| 488 |
+
|
| 489 |
+
/// Add standard basic block placement passes.
|
| 490 |
+
void addBlockPlacement(AddMachinePass &) const;
|
| 491 |
+
|
| 492 |
+
using CreateMCStreamer =
|
| 493 |
+
std::function<Expected<std::unique_ptr<MCStreamer>>(MCContext &)>;
|
| 494 |
+
void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const {
|
| 495 |
+
llvm_unreachable("addAsmPrinter is not overridden");
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
/// Utilities for targets to add passes to the pass manager.
|
| 499 |
+
///
|
| 500 |
+
|
| 501 |
+
/// createTargetRegisterAllocator - Create the register allocator pass for
|
| 502 |
+
/// this target at the current optimization level.
|
| 503 |
+
void addTargetRegisterAllocator(AddMachinePass &, bool Optimized) const;
|
| 504 |
+
|
| 505 |
+
/// addMachinePasses helper to create the target-selected or overriden
|
| 506 |
+
/// regalloc pass.
|
| 507 |
+
void addRegAllocPass(AddMachinePass &, bool Optimized) const;
|
| 508 |
+
|
| 509 |
+
/// Add core register alloator passes which do the actual register assignment
|
| 510 |
+
/// and rewriting. \returns true if any passes were added.
|
| 511 |
+
Error addRegAssignmentFast(AddMachinePass &) const;
|
| 512 |
+
Error addRegAssignmentOptimized(AddMachinePass &) const;
|
| 513 |
+
|
| 514 |
+
/// Allow the target to disable a specific pass by default.
|
| 515 |
+
/// Backend can declare unwanted passes in constructor.
|
| 516 |
+
template <typename... PassTs> void disablePass() {
|
| 517 |
+
BeforeCallbacks.emplace_back(
|
| 518 |
+
[](StringRef Name) { return ((Name != PassTs::name()) && ...); });
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
/// Insert InsertedPass pass after TargetPass pass.
|
| 522 |
+
/// Only machine function passes are supported.
|
| 523 |
+
template <typename TargetPassT, typename InsertedPassT>
|
| 524 |
+
void insertPass(InsertedPassT &&Pass) {
|
| 525 |
+
AfterCallbacks.emplace_back(
|
| 526 |
+
[&](StringRef Name, MachineFunctionPassManager &MFPM) mutable {
|
| 527 |
+
if (Name == TargetPassT::name())
|
| 528 |
+
MFPM.addPass(std::forward<InsertedPassT>(Pass));
|
| 529 |
+
});
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
private:
|
| 533 |
+
DerivedT &derived() { return static_cast<DerivedT &>(*this); }
|
| 534 |
+
const DerivedT &derived() const {
|
| 535 |
+
return static_cast<const DerivedT &>(*this);
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
bool runBeforeAdding(StringRef Name) const {
|
| 539 |
+
bool ShouldAdd = true;
|
| 540 |
+
for (auto &C : BeforeCallbacks)
|
| 541 |
+
ShouldAdd &= C(Name);
|
| 542 |
+
return ShouldAdd;
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
void setStartStopPasses(const TargetPassConfig::StartStopInfo &Info) const;
|
| 546 |
+
|
| 547 |
+
Error verifyStartStop(const TargetPassConfig::StartStopInfo &Info) const;
|
| 548 |
+
|
| 549 |
+
mutable SmallVector<llvm::unique_function<bool(StringRef)>, 4>
|
| 550 |
+
BeforeCallbacks;
|
| 551 |
+
mutable SmallVector<
|
| 552 |
+
llvm::unique_function<void(StringRef, MachineFunctionPassManager &)>, 4>
|
| 553 |
+
AfterCallbacks;
|
| 554 |
+
|
| 555 |
+
/// Helper variable for `-start-before/-start-after/-stop-before/-stop-after`
|
| 556 |
+
mutable bool Started = true;
|
| 557 |
+
mutable bool Stopped = true;
|
| 558 |
+
};
|
| 559 |
+
|
| 560 |
+
template <typename Derived, typename TargetMachineT>
|
| 561 |
+
Error CodeGenPassBuilder<Derived, TargetMachineT>::buildPipeline(
|
| 562 |
+
ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
|
| 563 |
+
CodeGenFileType FileType) const {
|
| 564 |
+
auto StartStopInfo = TargetPassConfig::getStartStopInfo(*PIC);
|
| 565 |
+
if (!StartStopInfo)
|
| 566 |
+
return StartStopInfo.takeError();
|
| 567 |
+
setStartStopPasses(*StartStopInfo);
|
| 568 |
+
|
| 569 |
+
bool PrintAsm = TargetPassConfig::willCompleteCodeGenPipeline();
|
| 570 |
+
bool PrintMIR = !PrintAsm && FileType != CodeGenFileType::Null;
|
| 571 |
+
|
| 572 |
+
{
|
| 573 |
+
AddIRPass addIRPass(MPM, derived());
|
| 574 |
+
addIRPass(RequireAnalysisPass<MachineModuleAnalysis, Module>());
|
| 575 |
+
addIRPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
|
| 576 |
+
addIRPass(RequireAnalysisPass<CollectorMetadataAnalysis, Module>());
|
| 577 |
+
addISelPasses(addIRPass);
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
AddMachinePass addPass(MPM, derived());
|
| 581 |
+
|
| 582 |
+
if (PrintMIR)
|
| 583 |
+
addPass(PrintMIRPreparePass(Out), /*Force=*/true);
|
| 584 |
+
|
| 585 |
+
if (auto Err = addCoreISelPasses(addPass))
|
| 586 |
+
return std::move(Err);
|
| 587 |
+
|
| 588 |
+
if (auto Err = derived().addMachinePasses(addPass))
|
| 589 |
+
return std::move(Err);
|
| 590 |
+
|
| 591 |
+
if (!Opt.DisableVerify)
|
| 592 |
+
addPass(MachineVerifierPass());
|
| 593 |
+
|
| 594 |
+
if (PrintAsm) {
|
| 595 |
+
derived().addAsmPrinter(
|
| 596 |
+
addPass, [this, &Out, DwoOut, FileType](MCContext &Ctx) {
|
| 597 |
+
return this->TM.createMCStreamer(Out, DwoOut, FileType, Ctx);
|
| 598 |
+
});
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
if (PrintMIR)
|
| 602 |
+
addPass(PrintMIRPass(Out), /*Force=*/true);
|
| 603 |
+
|
| 604 |
+
return verifyStartStop(*StartStopInfo);
|
| 605 |
+
}
|
| 606 |
+
|
| 607 |
+
template <typename Derived, typename TargetMachineT>
|
| 608 |
+
void CodeGenPassBuilder<Derived, TargetMachineT>::setStartStopPasses(
|
| 609 |
+
const TargetPassConfig::StartStopInfo &Info) const {
|
| 610 |
+
if (!Info.StartPass.empty()) {
|
| 611 |
+
Started = false;
|
| 612 |
+
BeforeCallbacks.emplace_back([this, &Info, AfterFlag = Info.StartAfter,
|
| 613 |
+
Count = 0u](StringRef ClassName) mutable {
|
| 614 |
+
if (Count == Info.StartInstanceNum) {
|
| 615 |
+
if (AfterFlag) {
|
| 616 |
+
AfterFlag = false;
|
| 617 |
+
Started = true;
|
| 618 |
+
}
|
| 619 |
+
return Started;
|
| 620 |
+
}
|
| 621 |
+
|
| 622 |
+
auto PassName = PIC->getPassNameForClassName(ClassName);
|
| 623 |
+
if (Info.StartPass == PassName && ++Count == Info.StartInstanceNum)
|
| 624 |
+
Started = !Info.StartAfter;
|
| 625 |
+
|
| 626 |
+
return Started;
|
| 627 |
+
});
|
| 628 |
+
}
|
| 629 |
+
|
| 630 |
+
if (!Info.StopPass.empty()) {
|
| 631 |
+
Stopped = false;
|
| 632 |
+
BeforeCallbacks.emplace_back([this, &Info, AfterFlag = Info.StopAfter,
|
| 633 |
+
Count = 0u](StringRef ClassName) mutable {
|
| 634 |
+
if (Count == Info.StopInstanceNum) {
|
| 635 |
+
if (AfterFlag) {
|
| 636 |
+
AfterFlag = false;
|
| 637 |
+
Stopped = true;
|
| 638 |
+
}
|
| 639 |
+
return !Stopped;
|
| 640 |
+
}
|
| 641 |
+
|
| 642 |
+
auto PassName = PIC->getPassNameForClassName(ClassName);
|
| 643 |
+
if (Info.StopPass == PassName && ++Count == Info.StopInstanceNum)
|
| 644 |
+
Stopped = !Info.StopAfter;
|
| 645 |
+
return !Stopped;
|
| 646 |
+
});
|
| 647 |
+
}
|
| 648 |
+
}
|
| 649 |
+
|
| 650 |
+
template <typename Derived, typename TargetMachineT>
|
| 651 |
+
Error CodeGenPassBuilder<Derived, TargetMachineT>::verifyStartStop(
|
| 652 |
+
const TargetPassConfig::StartStopInfo &Info) const {
|
| 653 |
+
if (Started && Stopped)
|
| 654 |
+
return Error::success();
|
| 655 |
+
|
| 656 |
+
if (!Started)
|
| 657 |
+
return make_error<StringError>(
|
| 658 |
+
"Can't find start pass \"" + Info.StartPass + "\".",
|
| 659 |
+
std::make_error_code(std::errc::invalid_argument));
|
| 660 |
+
if (!Stopped)
|
| 661 |
+
return make_error<StringError>(
|
| 662 |
+
"Can't find stop pass \"" + Info.StopPass + "\".",
|
| 663 |
+
std::make_error_code(std::errc::invalid_argument));
|
| 664 |
+
return Error::success();
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
template <typename Derived, typename TargetMachineT>
|
| 668 |
+
void CodeGenPassBuilder<Derived, TargetMachineT>::addISelPasses(
|
| 669 |
+
AddIRPass &addPass) const {
|
| 670 |
+
derived().addGlobalMergePass(addPass);
|
| 671 |
+
if (TM.useEmulatedTLS())
|
| 672 |
+
addPass(LowerEmuTLSPass());
|
| 673 |
+
|
| 674 |
+
addPass(PreISelIntrinsicLoweringPass(&TM));
|
| 675 |
+
addPass(ExpandLargeDivRemPass(&TM));
|
| 676 |
+
addPass(ExpandFpPass(&TM));
|
| 677 |
+
|
| 678 |
+
derived().addIRPasses(addPass);
|
| 679 |
+
derived().addCodeGenPrepare(addPass);
|
| 680 |
+
addPassesToHandleExceptions(addPass);
|
| 681 |
+
derived().addISelPrepare(addPass);
|
| 682 |
+
}
|
| 683 |
+
|
| 684 |
+
/// Add common target configurable passes that perform LLVM IR to IR transforms
|
| 685 |
+
/// following machine independent optimization.
|
| 686 |
+
template <typename Derived, typename TargetMachineT>
|
| 687 |
+
void CodeGenPassBuilder<Derived, TargetMachineT>::addIRPasses(
|
| 688 |
+
AddIRPass &addPass) const {
|
| 689 |
+
// Before running any passes, run the verifier to determine if the input
|
| 690 |
+
// coming from the front-end and/or optimizer is valid.
|
| 691 |
+
if (!Opt.DisableVerify)
|
| 692 |
+
addPass(VerifierPass());
|
| 693 |
+
|
| 694 |
+
// Run loop strength reduction before anything else.
|
| 695 |
+
if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableLSR) {
|
| 696 |
+
addPass(createFunctionToLoopPassAdaptor(LoopStrengthReducePass(),
|
| 697 |
+
/*UseMemorySSA=*/true));
|
| 698 |
+
}
|
| 699 |
+
|
| 700 |
+
if (getOptLevel() != CodeGenOptLevel::None) {
|
| 701 |
+
// The MergeICmpsPass tries to create memcmp calls by grouping sequences of
|
| 702 |
+
// loads and compares. ExpandMemCmpPass then tries to expand those calls
|
| 703 |
+
// into optimally-sized loads and compares. The transforms are enabled by a
|
| 704 |
+
// target lowering hook.
|
| 705 |
+
if (!Opt.DisableMergeICmps)
|
| 706 |
+
addPass(MergeICmpsPass());
|
| 707 |
+
addPass(ExpandMemCmpPass(&TM));
|
| 708 |
+
}
|
| 709 |
+
|
| 710 |
+
// Run GC lowering passes for builtin collectors
|
| 711 |
+
// TODO: add a pass insertion point here
|
| 712 |
+
addPass(GCLoweringPass());
|
| 713 |
+
addPass(ShadowStackGCLoweringPass());
|
| 714 |
+
addPass(LowerConstantIntrinsicsPass());
|
| 715 |
+
|
| 716 |
+
// Make sure that no unreachable blocks are instruction selected.
|
| 717 |
+
addPass(UnreachableBlockElimPass());
|
| 718 |
+
|
| 719 |
+
// Prepare expensive constants for SelectionDAG.
|
| 720 |
+
if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableConstantHoisting)
|
| 721 |
+
addPass(ConstantHoistingPass());
|
| 722 |
+
|
| 723 |
+
// Replace calls to LLVM intrinsics (e.g., exp, log) operating on vector
|
| 724 |
+
// operands with calls to the corresponding functions in a vector library.
|
| 725 |
+
if (getOptLevel() != CodeGenOptLevel::None)
|
| 726 |
+
addPass(ReplaceWithVeclib());
|
| 727 |
+
|
| 728 |
+
if (getOptLevel() != CodeGenOptLevel::None &&
|
| 729 |
+
!Opt.DisablePartialLibcallInlining)
|
| 730 |
+
addPass(PartiallyInlineLibCallsPass());
|
| 731 |
+
|
| 732 |
+
// Instrument function entry and exit, e.g. with calls to mcount().
|
| 733 |
+
addPass(EntryExitInstrumenterPass(/*PostInlining=*/true));
|
| 734 |
+
|
| 735 |
+
// Add scalarization of target's unsupported masked memory intrinsics pass.
|
| 736 |
+
// the unsupported intrinsic will be replaced with a chain of basic blocks,
|
| 737 |
+
// that stores/loads element one-by-one if the appropriate mask bit is set.
|
| 738 |
+
addPass(ScalarizeMaskedMemIntrinPass());
|
| 739 |
+
|
| 740 |
+
// Expand reduction intrinsics into shuffle sequences if the target wants to.
|
| 741 |
+
addPass(ExpandReductionsPass());
|
| 742 |
+
|
| 743 |
+
// Convert conditional moves to conditional jumps when profitable.
|
| 744 |
+
if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableSelectOptimize)
|
| 745 |
+
addPass(SelectOptimizePass(&TM));
|
| 746 |
+
|
| 747 |
+
if (Opt.EnableGlobalMergeFunc)
|
| 748 |
+
addPass(GlobalMergeFuncPass());
|
| 749 |
+
}
|
| 750 |
+
|
| 751 |
+
/// Turn exception handling constructs into something the code generators can
|
| 752 |
+
/// handle.
|
| 753 |
+
template <typename Derived, typename TargetMachineT>
|
| 754 |
+
void CodeGenPassBuilder<Derived, TargetMachineT>::addPassesToHandleExceptions(
|
| 755 |
+
AddIRPass &addPass) const {
|
| 756 |
+
const MCAsmInfo *MCAI = TM.getMCAsmInfo();
|
| 757 |
+
assert(MCAI && "No MCAsmInfo");
|
| 758 |
+
switch (MCAI->getExceptionHandlingType()) {
|
| 759 |
+
case ExceptionHandling::SjLj:
|
| 760 |
+
// SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
|
| 761 |
+
// Dwarf EH prepare needs to be run after SjLj prepare. Otherwise,
|
| 762 |
+
// catch info can get misplaced when a selector ends up more than one block
|
| 763 |
+
// removed from the parent invoke(s). This could happen when a landing
|
| 764 |
+
// pad is shared by multiple invokes and is also a target of a normal
|
| 765 |
+
// edge from elsewhere.
|
| 766 |
+
addPass(SjLjEHPreparePass(&TM));
|
| 767 |
+
[[fallthrough]];
|
| 768 |
+
case ExceptionHandling::DwarfCFI:
|
| 769 |
+
case ExceptionHandling::ARM:
|
| 770 |
+
case ExceptionHandling::AIX:
|
| 771 |
+
case ExceptionHandling::ZOS:
|
| 772 |
+
addPass(DwarfEHPreparePass(&TM));
|
| 773 |
+
break;
|
| 774 |
+
case ExceptionHandling::WinEH:
|
| 775 |
+
// We support using both GCC-style and MSVC-style exceptions on Windows, so
|
| 776 |
+
// add both preparation passes. Each pass will only actually run if it
|
| 777 |
+
// recognizes the personality function.
|
| 778 |
+
addPass(WinEHPreparePass());
|
| 779 |
+
addPass(DwarfEHPreparePass(&TM));
|
| 780 |
+
break;
|
| 781 |
+
case ExceptionHandling::Wasm:
|
| 782 |
+
// Wasm EH uses Windows EH instructions, but it does not need to demote PHIs
|
| 783 |
+
// on catchpads and cleanuppads because it does not outline them into
|
| 784 |
+
// funclets. Catchswitch blocks are not lowered in SelectionDAG, so we
|
| 785 |
+
// should remove PHIs there.
|
| 786 |
+
addPass(WinEHPreparePass(/*DemoteCatchSwitchPHIOnly=*/false));
|
| 787 |
+
addPass(WasmEHPreparePass());
|
| 788 |
+
break;
|
| 789 |
+
case ExceptionHandling::None:
|
| 790 |
+
addPass(LowerInvokePass());
|
| 791 |
+
|
| 792 |
+
// The lower invoke pass may create unreachable code. Remove it.
|
| 793 |
+
addPass(UnreachableBlockElimPass());
|
| 794 |
+
break;
|
| 795 |
+
}
|
| 796 |
+
}
|
| 797 |
+
|
| 798 |
+
/// Add pass to prepare the LLVM IR for code generation. This should be done
|
| 799 |
+
/// before exception handling preparation passes.
|
| 800 |
+
template <typename Derived, typename TargetMachineT>
|
| 801 |
+
void CodeGenPassBuilder<Derived, TargetMachineT>::addCodeGenPrepare(
|
| 802 |
+
AddIRPass &addPass) const {
|
| 803 |
+
if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableCGP)
|
| 804 |
+
addPass(CodeGenPreparePass(&TM));
|
| 805 |
+
// TODO: Default ctor'd RewriteSymbolPass is no-op.
|
| 806 |
+
// addPass(RewriteSymbolPass());
|
| 807 |
+
}
|
| 808 |
+
|
| 809 |
+
/// Add common passes that perform LLVM IR to IR transforms in preparation for
|
| 810 |
+
/// instruction selection.
|
| 811 |
+
template <typename Derived, typename TargetMachineT>
|
| 812 |
+
void CodeGenPassBuilder<Derived, TargetMachineT>::addISelPrepare(
|
| 813 |
+
AddIRPass &addPass) const {
|
| 814 |
+
derived().addPreISel(addPass);
|
| 815 |
+
|
| 816 |
+
addPass(CallBrPreparePass());
|
| 817 |
+
// Add both the safe stack and the stack protection passes: each of them will
|
| 818 |
+
// only protect functions that have corresponding attributes.
|
| 819 |
+
addPass(SafeStackPass(&TM));
|
| 820 |
+
addPass(StackProtectorPass(&TM));
|
| 821 |
+
|
| 822 |
+
if (Opt.PrintISelInput)
|
| 823 |
+
addPass(PrintFunctionPass(dbgs(),
|
| 824 |
+
"\n\n*** Final LLVM Code input to ISel ***\n"));
|
| 825 |
+
|
| 826 |
+
// All passes which modify the LLVM IR are now complete; run the verifier
|
| 827 |
+
// to ensure that the IR is valid.
|
| 828 |
+
if (!Opt.DisableVerify)
|
| 829 |
+
addPass(VerifierPass());
|
| 830 |
+
}
|
| 831 |
+
|
| 832 |
+
template <typename Derived, typename TargetMachineT>
|
| 833 |
+
Error CodeGenPassBuilder<Derived, TargetMachineT>::addCoreISelPasses(
|
| 834 |
+
AddMachinePass &addPass) const {
|
| 835 |
+
// Enable FastISel with -fast-isel, but allow that to be overridden.
|
| 836 |
+
TM.setO0WantsFastISel(Opt.EnableFastISelOption.value_or(true));
|
| 837 |
+
|
| 838 |
+
// Determine an instruction selector.
|
| 839 |
+
enum class SelectorType { SelectionDAG, FastISel, GlobalISel };
|
| 840 |
+
SelectorType Selector;
|
| 841 |
+
|
| 842 |
+
if (Opt.EnableFastISelOption && *Opt.EnableFastISelOption == true)
|
| 843 |
+
Selector = SelectorType::FastISel;
|
| 844 |
+
else if ((Opt.EnableGlobalISelOption &&
|
| 845 |
+
*Opt.EnableGlobalISelOption == true) ||
|
| 846 |
+
(TM.Options.EnableGlobalISel &&
|
| 847 |
+
(!Opt.EnableGlobalISelOption ||
|
| 848 |
+
*Opt.EnableGlobalISelOption == false)))
|
| 849 |
+
Selector = SelectorType::GlobalISel;
|
| 850 |
+
else if (TM.getOptLevel() == CodeGenOptLevel::None && TM.getO0WantsFastISel())
|
| 851 |
+
Selector = SelectorType::FastISel;
|
| 852 |
+
else
|
| 853 |
+
Selector = SelectorType::SelectionDAG;
|
| 854 |
+
|
| 855 |
+
// Set consistently TM.Options.EnableFastISel and EnableGlobalISel.
|
| 856 |
+
if (Selector == SelectorType::FastISel) {
|
| 857 |
+
TM.setFastISel(true);
|
| 858 |
+
TM.setGlobalISel(false);
|
| 859 |
+
} else if (Selector == SelectorType::GlobalISel) {
|
| 860 |
+
TM.setFastISel(false);
|
| 861 |
+
TM.setGlobalISel(true);
|
| 862 |
+
}
|
| 863 |
+
|
| 864 |
+
// Add instruction selector passes.
|
| 865 |
+
if (Selector == SelectorType::GlobalISel) {
|
| 866 |
+
if (auto Err = derived().addIRTranslator(addPass))
|
| 867 |
+
return std::move(Err);
|
| 868 |
+
|
| 869 |
+
derived().addPreLegalizeMachineIR(addPass);
|
| 870 |
+
|
| 871 |
+
if (auto Err = derived().addLegalizeMachineIR(addPass))
|
| 872 |
+
return std::move(Err);
|
| 873 |
+
|
| 874 |
+
// Before running the register bank selector, ask the target if it
|
| 875 |
+
// wants to run some passes.
|
| 876 |
+
derived().addPreRegBankSelect(addPass);
|
| 877 |
+
|
| 878 |
+
if (auto Err = derived().addRegBankSelect(addPass))
|
| 879 |
+
return std::move(Err);
|
| 880 |
+
|
| 881 |
+
derived().addPreGlobalInstructionSelect(addPass);
|
| 882 |
+
|
| 883 |
+
if (auto Err = derived().addGlobalInstructionSelect(addPass))
|
| 884 |
+
return std::move(Err);
|
| 885 |
+
|
| 886 |
+
// Pass to reset the MachineFunction if the ISel failed.
|
| 887 |
+
addPass(ResetMachineFunctionPass(reportDiagnosticWhenGlobalISelFallback(),
|
| 888 |
+
isGlobalISelAbortEnabled()));
|
| 889 |
+
|
| 890 |
+
// Provide a fallback path when we do not want to abort on
|
| 891 |
+
// not-yet-supported input.
|
| 892 |
+
if (!isGlobalISelAbortEnabled())
|
| 893 |
+
if (auto Err = derived().addInstSelector(addPass))
|
| 894 |
+
return std::move(Err);
|
| 895 |
+
|
| 896 |
+
} else if (auto Err = derived().addInstSelector(addPass))
|
| 897 |
+
return std::move(Err);
|
| 898 |
+
|
| 899 |
+
// Expand pseudo-instructions emitted by ISel. Don't run the verifier before
|
| 900 |
+
// FinalizeISel.
|
| 901 |
+
addPass(FinalizeISelPass());
|
| 902 |
+
|
| 903 |
+
// // Print the instruction selected machine code...
|
| 904 |
+
// printAndVerify("After Instruction Selection");
|
| 905 |
+
|
| 906 |
+
return Error::success();
|
| 907 |
+
}
|
| 908 |
+
|
| 909 |
+
/// Add the complete set of target-independent postISel code generator passes.
|
| 910 |
+
///
|
| 911 |
+
/// This can be read as the standard order of major LLVM CodeGen stages. Stages
|
| 912 |
+
/// with nontrivial configuration or multiple passes are broken out below in
|
| 913 |
+
/// add%Stage routines.
|
| 914 |
+
///
|
| 915 |
+
/// Any CodeGenPassBuilder<Derived, TargetMachine>::addXX routine may be
|
| 916 |
+
/// overriden by the Target. The addPre/Post methods with empty header
|
| 917 |
+
/// implementations allow injecting target-specific fixups just before or after
|
| 918 |
+
/// major stages. Additionally, targets have the flexibility to change pass
|
| 919 |
+
/// order within a stage by overriding default implementation of add%Stage
|
| 920 |
+
/// routines below. Each technique has maintainability tradeoffs because
|
| 921 |
+
/// alternate pass orders are not well supported. addPre/Post works better if
|
| 922 |
+
/// the target pass is easily tied to a common pass. But if it has subtle
|
| 923 |
+
/// dependencies on multiple passes, the target should override the stage
|
| 924 |
+
/// instead.
|
| 925 |
+
template <typename Derived, typename TargetMachineT>
|
| 926 |
+
Error CodeGenPassBuilder<Derived, TargetMachineT>::addMachinePasses(
|
| 927 |
+
AddMachinePass &addPass) const {
|
| 928 |
+
// Add passes that optimize machine instructions in SSA form.
|
| 929 |
+
if (getOptLevel() != CodeGenOptLevel::None) {
|
| 930 |
+
derived().addMachineSSAOptimization(addPass);
|
| 931 |
+
} else {
|
| 932 |
+
// If the target requests it, assign local variables to stack slots relative
|
| 933 |
+
// to one another and simplify frame index references where possible.
|
| 934 |
+
addPass(LocalStackSlotAllocationPass());
|
| 935 |
+
}
|
| 936 |
+
|
| 937 |
+
if (TM.Options.EnableIPRA) {
|
| 938 |
+
addPass(RequireAnalysisPass<PhysicalRegisterUsageAnalysis, Module>());
|
| 939 |
+
addPass(RegUsageInfoPropagationPass());
|
| 940 |
+
}
|
| 941 |
+
// Run pre-ra passes.
|
| 942 |
+
derived().addPreRegAlloc(addPass);
|
| 943 |
+
|
| 944 |
+
// Run register allocation and passes that are tightly coupled with it,
|
| 945 |
+
// including phi elimination and scheduling.
|
| 946 |
+
if (*Opt.OptimizeRegAlloc) {
|
| 947 |
+
derived().addOptimizedRegAlloc(addPass);
|
| 948 |
+
} else {
|
| 949 |
+
if (auto Err = derived().addFastRegAlloc(addPass))
|
| 950 |
+
return Err;
|
| 951 |
+
}
|
| 952 |
+
|
| 953 |
+
// Run post-ra passes.
|
| 954 |
+
derived().addPostRegAlloc(addPass);
|
| 955 |
+
|
| 956 |
+
addPass(RemoveRedundantDebugValuesPass());
|
| 957 |
+
addPass(FixupStatepointCallerSavedPass());
|
| 958 |
+
|
| 959 |
+
// Insert prolog/epilog code. Eliminate abstract frame index references...
|
| 960 |
+
if (getOptLevel() != CodeGenOptLevel::None) {
|
| 961 |
+
addPass(PostRAMachineSinkingPass());
|
| 962 |
+
addPass(ShrinkWrapPass());
|
| 963 |
+
}
|
| 964 |
+
|
| 965 |
+
addPass(PrologEpilogInserterPass());
|
| 966 |
+
|
| 967 |
+
/// Add passes that optimize machine instructions after register allocation.
|
| 968 |
+
if (getOptLevel() != CodeGenOptLevel::None)
|
| 969 |
+
derived().addMachineLateOptimization(addPass);
|
| 970 |
+
|
| 971 |
+
// Expand pseudo instructions before second scheduling pass.
|
| 972 |
+
addPass(ExpandPostRAPseudosPass());
|
| 973 |
+
|
| 974 |
+
// Run pre-sched2 passes.
|
| 975 |
+
derived().addPreSched2(addPass);
|
| 976 |
+
|
| 977 |
+
if (Opt.EnableImplicitNullChecks)
|
| 978 |
+
addPass(ImplicitNullChecksPass());
|
| 979 |
+
|
| 980 |
+
// Second pass scheduler.
|
| 981 |
+
// Let Target optionally insert this pass by itself at some other
|
| 982 |
+
// point.
|
| 983 |
+
if (getOptLevel() != CodeGenOptLevel::None &&
|
| 984 |
+
!TM.targetSchedulesPostRAScheduling()) {
|
| 985 |
+
if (Opt.MISchedPostRA)
|
| 986 |
+
addPass(PostMachineSchedulerPass(&TM));
|
| 987 |
+
else
|
| 988 |
+
addPass(PostRASchedulerPass(&TM));
|
| 989 |
+
}
|
| 990 |
+
|
| 991 |
+
// GC
|
| 992 |
+
derived().addGCPasses(addPass);
|
| 993 |
+
|
| 994 |
+
// Basic block placement.
|
| 995 |
+
if (getOptLevel() != CodeGenOptLevel::None)
|
| 996 |
+
derived().addBlockPlacement(addPass);
|
| 997 |
+
|
| 998 |
+
// Insert before XRay Instrumentation.
|
| 999 |
+
addPass(FEntryInserterPass());
|
| 1000 |
+
|
| 1001 |
+
addPass(XRayInstrumentationPass());
|
| 1002 |
+
addPass(PatchableFunctionPass());
|
| 1003 |
+
|
| 1004 |
+
derived().addPreEmitPass(addPass);
|
| 1005 |
+
|
| 1006 |
+
if (TM.Options.EnableIPRA)
|
| 1007 |
+
// Collect register usage information and produce a register mask of
|
| 1008 |
+
// clobbered registers, to be used to optimize call sites.
|
| 1009 |
+
addPass(RegUsageInfoCollectorPass());
|
| 1010 |
+
|
| 1011 |
+
addPass(FuncletLayoutPass());
|
| 1012 |
+
|
| 1013 |
+
addPass(RemoveLoadsIntoFakeUsesPass());
|
| 1014 |
+
addPass(StackMapLivenessPass());
|
| 1015 |
+
addPass(LiveDebugValuesPass(
|
| 1016 |
+
getTM<TargetMachine>().Options.ShouldEmitDebugEntryValues()));
|
| 1017 |
+
addPass(MachineSanitizerBinaryMetadataPass());
|
| 1018 |
+
|
| 1019 |
+
if (TM.Options.EnableMachineOutliner &&
|
| 1020 |
+
getOptLevel() != CodeGenOptLevel::None &&
|
| 1021 |
+
Opt.EnableMachineOutliner != RunOutliner::NeverOutline) {
|
| 1022 |
+
bool RunOnAllFunctions =
|
| 1023 |
+
(Opt.EnableMachineOutliner == RunOutliner::AlwaysOutline);
|
| 1024 |
+
bool AddOutliner = RunOnAllFunctions || TM.Options.SupportsDefaultOutlining;
|
| 1025 |
+
if (AddOutliner)
|
| 1026 |
+
addPass(MachineOutlinerPass(RunOnAllFunctions));
|
| 1027 |
+
}
|
| 1028 |
+
|
| 1029 |
+
addPass(StackFrameLayoutAnalysisPass());
|
| 1030 |
+
|
| 1031 |
+
// Add passes that directly emit MI after all other MI passes.
|
| 1032 |
+
derived().addPreEmitPass2(addPass);
|
| 1033 |
+
|
| 1034 |
+
return Error::success();
|
| 1035 |
+
}
|
| 1036 |
+
|
| 1037 |
+
/// Add passes that optimize machine instructions in SSA form.
|
| 1038 |
+
template <typename Derived, typename TargetMachineT>
|
| 1039 |
+
void CodeGenPassBuilder<Derived, TargetMachineT>::addMachineSSAOptimization(
|
| 1040 |
+
AddMachinePass &addPass) const {
|
| 1041 |
+
// Pre-ra tail duplication.
|
| 1042 |
+
addPass(EarlyTailDuplicatePass());
|
| 1043 |
+
|
| 1044 |
+
// Optimize PHIs before DCE: removing dead PHI cycles may make more
|
| 1045 |
+
// instructions dead.
|
| 1046 |
+
addPass(OptimizePHIsPass());
|
| 1047 |
+
|
| 1048 |
+
// This pass merges large allocas. StackSlotColoring is a different pass
|
| 1049 |
+
// which merges spill slots.
|
| 1050 |
+
addPass(StackColoringPass());
|
| 1051 |
+
|
| 1052 |
+
// If the target requests it, assign local variables to stack slots relative
|
| 1053 |
+
// to one another and simplify frame index references where possible.
|
| 1054 |
+
addPass(LocalStackSlotAllocationPass());
|
| 1055 |
+
|
| 1056 |
+
// With optimization, dead code should already be eliminated. However
|
| 1057 |
+
// there is one known exception: lowered code for arguments that are only
|
| 1058 |
+
// used by tail calls, where the tail calls reuse the incoming stack
|
| 1059 |
+
// arguments directly (see t11 in test/CodeGen/X86/sibcall.ll).
|
| 1060 |
+
addPass(DeadMachineInstructionElimPass());
|
| 1061 |
+
|
| 1062 |
+
// Allow targets to insert passes that improve instruction level parallelism,
|
| 1063 |
+
// like if-conversion. Such passes will typically need dominator trees and
|
| 1064 |
+
// loop info, just like LICM and CSE below.
|
| 1065 |
+
derived().addILPOpts(addPass);
|
| 1066 |
+
|
| 1067 |
+
addPass(EarlyMachineLICMPass());
|
| 1068 |
+
addPass(MachineCSEPass());
|
| 1069 |
+
|
| 1070 |
+
addPass(MachineSinkingPass(Opt.EnableSinkAndFold));
|
| 1071 |
+
|
| 1072 |
+
addPass(PeepholeOptimizerPass());
|
| 1073 |
+
// Clean-up the dead code that may have been generated by peephole
|
| 1074 |
+
// rewriting.
|
| 1075 |
+
addPass(DeadMachineInstructionElimPass());
|
| 1076 |
+
}
|
| 1077 |
+
|
| 1078 |
+
//===---------------------------------------------------------------------===//
|
| 1079 |
+
/// Register Allocation Pass Configuration
|
| 1080 |
+
//===---------------------------------------------------------------------===//
|
| 1081 |
+
|
| 1082 |
+
/// Instantiate the default register allocator pass for this target for either
|
| 1083 |
+
/// the optimized or unoptimized allocation path. This will be added to the pass
|
| 1084 |
+
/// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc
|
| 1085 |
+
/// in the optimized case.
|
| 1086 |
+
///
|
| 1087 |
+
/// A target that uses the standard regalloc pass order for fast or optimized
|
| 1088 |
+
/// allocation may still override this for per-target regalloc
|
| 1089 |
+
/// selection. But -regalloc-npm=... always takes precedence.
|
| 1090 |
+
/// If a target does not want to allow users to set -regalloc-npm=... at all,
|
| 1091 |
+
/// check if Opt.RegAlloc == RegAllocType::Unset.
|
| 1092 |
+
template <typename Derived, typename TargetMachineT>
|
| 1093 |
+
void CodeGenPassBuilder<Derived, TargetMachineT>::addTargetRegisterAllocator(
|
| 1094 |
+
AddMachinePass &addPass, bool Optimized) const {
|
| 1095 |
+
if (Optimized)
|
| 1096 |
+
addPass(RAGreedyPass());
|
| 1097 |
+
else
|
| 1098 |
+
addPass(RegAllocFastPass());
|
| 1099 |
+
}
|
| 1100 |
+
|
| 1101 |
+
/// Find and instantiate the register allocation pass requested by this target
|
| 1102 |
+
/// at the current optimization level. Different register allocators are
|
| 1103 |
+
/// defined as separate passes because they may require different analysis.
|
| 1104 |
+
///
|
| 1105 |
+
/// This helper ensures that the -regalloc-npm= option is always available,
|
| 1106 |
+
/// even for targets that override the default allocator.
|
| 1107 |
+
template <typename Derived, typename TargetMachineT>
|
| 1108 |
+
void CodeGenPassBuilder<Derived, TargetMachineT>::addRegAllocPass(
|
| 1109 |
+
AddMachinePass &addPass, bool Optimized) const {
|
| 1110 |
+
// Use the specified -regalloc-npm={basic|greedy|fast|pbqp}
|
| 1111 |
+
if (Opt.RegAlloc > RegAllocType::Default) {
|
| 1112 |
+
switch (Opt.RegAlloc) {
|
| 1113 |
+
case RegAllocType::Fast:
|
| 1114 |
+
addPass(RegAllocFastPass());
|
| 1115 |
+
break;
|
| 1116 |
+
case RegAllocType::Greedy:
|
| 1117 |
+
addPass(RAGreedyPass());
|
| 1118 |
+
break;
|
| 1119 |
+
default:
|
| 1120 |
+
reportFatalUsageError("register allocator not supported yet");
|
| 1121 |
+
}
|
| 1122 |
+
return;
|
| 1123 |
+
}
|
| 1124 |
+
// -regalloc=default or unspecified, so pick based on the optimization level
|
| 1125 |
+
// or ask the target for the regalloc pass.
|
| 1126 |
+
derived().addTargetRegisterAllocator(addPass, Optimized);
|
| 1127 |
+
}
|
| 1128 |
+
|
| 1129 |
+
template <typename Derived, typename TargetMachineT>
|
| 1130 |
+
Error CodeGenPassBuilder<Derived, TargetMachineT>::addRegAssignmentFast(
|
| 1131 |
+
AddMachinePass &addPass) const {
|
| 1132 |
+
// TODO: Ensure allocator is default or fast.
|
| 1133 |
+
addRegAllocPass(addPass, false);
|
| 1134 |
+
return Error::success();
|
| 1135 |
+
}
|
| 1136 |
+
|
| 1137 |
+
template <typename Derived, typename TargetMachineT>
|
| 1138 |
+
Error CodeGenPassBuilder<Derived, TargetMachineT>::addRegAssignmentOptimized(
|
| 1139 |
+
AddMachinePass &addPass) const {
|
| 1140 |
+
// Add the selected register allocation pass.
|
| 1141 |
+
addRegAllocPass(addPass, true);
|
| 1142 |
+
|
| 1143 |
+
// Allow targets to change the register assignments before rewriting.
|
| 1144 |
+
derived().addPreRewrite(addPass);
|
| 1145 |
+
|
| 1146 |
+
// Finally rewrite virtual registers.
|
| 1147 |
+
addPass(VirtRegRewriterPass());
|
| 1148 |
+
// Perform stack slot coloring and post-ra machine LICM.
|
| 1149 |
+
//
|
| 1150 |
+
// FIXME: Re-enable coloring with register when it's capable of adding
|
| 1151 |
+
// kill markers.
|
| 1152 |
+
addPass(StackSlotColoringPass());
|
| 1153 |
+
|
| 1154 |
+
return Error::success();
|
| 1155 |
+
}
|
| 1156 |
+
|
| 1157 |
+
/// Add the minimum set of target-independent passes that are required for
|
| 1158 |
+
/// register allocation. No coalescing or scheduling.
|
| 1159 |
+
template <typename Derived, typename TargetMachineT>
|
| 1160 |
+
Error CodeGenPassBuilder<Derived, TargetMachineT>::addFastRegAlloc(
|
| 1161 |
+
AddMachinePass &addPass) const {
|
| 1162 |
+
addPass(PHIEliminationPass());
|
| 1163 |
+
addPass(TwoAddressInstructionPass());
|
| 1164 |
+
return derived().addRegAssignmentFast(addPass);
|
| 1165 |
+
}
|
| 1166 |
+
|
| 1167 |
+
/// Add standard target-independent passes that are tightly coupled with
|
| 1168 |
+
/// optimized register allocation, including coalescing, machine instruction
|
| 1169 |
+
/// scheduling, and register allocation itself.
|
| 1170 |
+
template <typename Derived, typename TargetMachineT>
|
| 1171 |
+
void CodeGenPassBuilder<Derived, TargetMachineT>::addOptimizedRegAlloc(
|
| 1172 |
+
AddMachinePass &addPass) const {
|
| 1173 |
+
addPass(DetectDeadLanesPass());
|
| 1174 |
+
|
| 1175 |
+
addPass(InitUndefPass());
|
| 1176 |
+
|
| 1177 |
+
addPass(ProcessImplicitDefsPass());
|
| 1178 |
+
|
| 1179 |
+
// LiveVariables currently requires pure SSA form.
|
| 1180 |
+
//
|
| 1181 |
+
// FIXME: Once TwoAddressInstruction pass no longer uses kill flags,
|
| 1182 |
+
// LiveVariables can be removed completely, and LiveIntervals can be directly
|
| 1183 |
+
// computed. (We still either need to regenerate kill flags after regalloc, or
|
| 1184 |
+
// preferably fix the scavenger to not depend on them).
|
| 1185 |
+
// FIXME: UnreachableMachineBlockElim is a dependant pass of LiveVariables.
|
| 1186 |
+
// When LiveVariables is removed this has to be removed/moved either.
|
| 1187 |
+
// Explicit addition of UnreachableMachineBlockElim allows stopping before or
|
| 1188 |
+
// after it with -stop-before/-stop-after.
|
| 1189 |
+
addPass(UnreachableMachineBlockElimPass());
|
| 1190 |
+
addPass(RequireAnalysisPass<LiveVariablesAnalysis, MachineFunction>());
|
| 1191 |
+
|
| 1192 |
+
// Edge splitting is smarter with machine loop info.
|
| 1193 |
+
addPass(RequireAnalysisPass<MachineLoopAnalysis, MachineFunction>());
|
| 1194 |
+
addPass(PHIEliminationPass());
|
| 1195 |
+
|
| 1196 |
+
// Eventually, we want to run LiveIntervals before PHI elimination.
|
| 1197 |
+
if (Opt.EarlyLiveIntervals)
|
| 1198 |
+
addPass(RequireAnalysisPass<LiveIntervalsAnalysis, MachineFunction>());
|
| 1199 |
+
|
| 1200 |
+
addPass(TwoAddressInstructionPass());
|
| 1201 |
+
addPass(RegisterCoalescerPass());
|
| 1202 |
+
|
| 1203 |
+
// The machine scheduler may accidentally create disconnected components
|
| 1204 |
+
// when moving subregister definitions around, avoid this by splitting them to
|
| 1205 |
+
// separate vregs before. Splitting can also improve reg. allocation quality.
|
| 1206 |
+
addPass(RenameIndependentSubregsPass());
|
| 1207 |
+
|
| 1208 |
+
// PreRA instruction scheduling.
|
| 1209 |
+
addPass(MachineSchedulerPass(&TM));
|
| 1210 |
+
|
| 1211 |
+
if (auto E = derived().addRegAssignmentOptimized(addPass)) {
|
| 1212 |
+
// addRegAssignmentOptimized did not add a reg alloc pass, so do nothing.
|
| 1213 |
+
return;
|
| 1214 |
+
}
|
| 1215 |
+
// Allow targets to expand pseudo instructions depending on the choice of
|
| 1216 |
+
// registers before MachineCopyPropagation.
|
| 1217 |
+
derived().addPostRewrite(addPass);
|
| 1218 |
+
|
| 1219 |
+
// Copy propagate to forward register uses and try to eliminate COPYs that
|
| 1220 |
+
// were not coalesced.
|
| 1221 |
+
addPass(MachineCopyPropagationPass());
|
| 1222 |
+
|
| 1223 |
+
// Run post-ra machine LICM to hoist reloads / remats.
|
| 1224 |
+
//
|
| 1225 |
+
// FIXME: can this move into MachineLateOptimization?
|
| 1226 |
+
addPass(MachineLICMPass());
|
| 1227 |
+
}
|
| 1228 |
+
|
| 1229 |
+
//===---------------------------------------------------------------------===//
|
| 1230 |
+
/// Post RegAlloc Pass Configuration
|
| 1231 |
+
//===---------------------------------------------------------------------===//
|
| 1232 |
+
|
| 1233 |
+
/// Add passes that optimize machine instructions after register allocation.
|
| 1234 |
+
template <typename Derived, typename TargetMachineT>
|
| 1235 |
+
void CodeGenPassBuilder<Derived, TargetMachineT>::addMachineLateOptimization(
|
| 1236 |
+
AddMachinePass &addPass) const {
|
| 1237 |
+
// Branch folding must be run after regalloc and prolog/epilog insertion.
|
| 1238 |
+
addPass(BranchFolderPass(Opt.EnableTailMerge));
|
| 1239 |
+
|
| 1240 |
+
// Tail duplication.
|
| 1241 |
+
// Note that duplicating tail just increases code size and degrades
|
| 1242 |
+
// performance for targets that require Structured Control Flow.
|
| 1243 |
+
// In addition it can also make CFG irreducible. Thus we disable it.
|
| 1244 |
+
if (!TM.requiresStructuredCFG())
|
| 1245 |
+
addPass(TailDuplicatePass());
|
| 1246 |
+
|
| 1247 |
+
// Cleanup of redundant (identical) address/immediate loads.
|
| 1248 |
+
addPass(MachineLateInstrsCleanupPass());
|
| 1249 |
+
|
| 1250 |
+
// Copy propagation.
|
| 1251 |
+
addPass(MachineCopyPropagationPass());
|
| 1252 |
+
}
|
| 1253 |
+
|
| 1254 |
+
/// Add standard basic block placement passes.
|
| 1255 |
+
template <typename Derived, typename TargetMachineT>
|
| 1256 |
+
void CodeGenPassBuilder<Derived, TargetMachineT>::addBlockPlacement(
|
| 1257 |
+
AddMachinePass &addPass) const {
|
| 1258 |
+
addPass(MachineBlockPlacementPass(Opt.EnableTailMerge));
|
| 1259 |
+
// Run a separate pass to collect block placement statistics.
|
| 1260 |
+
if (Opt.EnableBlockPlacementStats)
|
| 1261 |
+
addPass(MachineBlockPlacementStatsPass());
|
| 1262 |
+
}
|
| 1263 |
+
|
| 1264 |
+
} // namespace llvm
|
| 1265 |
+
|
| 1266 |
+
#endif // LLVM_PASSES_CODEGENPASSBUILDER_H
|
deps/exla/cache/xla_extension/include/llvm/Passes/MachinePassRegistry.def
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- MachinePassRegistry.def - Registry of passes -------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file is used as the registry of passes that are for target-independent
|
| 10 |
+
// code generator.
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
// NOTE: NO INCLUDE GUARD DESIRED!
|
| 15 |
+
|
| 16 |
+
#ifndef MODULE_ANALYSIS
|
| 17 |
+
#define MODULE_ANALYSIS(NAME, CREATE_PASS)
|
| 18 |
+
#endif
|
| 19 |
+
MODULE_ANALYSIS("collector-metadata", CollectorMetadataAnalysis())
|
| 20 |
+
MODULE_ANALYSIS("machine-module-info", MachineModuleAnalysis())
|
| 21 |
+
MODULE_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))
|
| 22 |
+
#undef MODULE_ANALYSIS
|
| 23 |
+
|
| 24 |
+
#ifndef MODULE_PASS
|
| 25 |
+
#define MODULE_PASS(NAME, CREATE_PASS)
|
| 26 |
+
#endif
|
| 27 |
+
MODULE_PASS("global-merge", GlobalMergePass(TM, GlobalMergeOptions()))
|
| 28 |
+
MODULE_PASS("jmc-instrumenter", JMCInstrumenterPass())
|
| 29 |
+
MODULE_PASS("lower-emutls", LowerEmuTLSPass())
|
| 30 |
+
MODULE_PASS("pre-isel-intrinsic-lowering", PreISelIntrinsicLoweringPass())
|
| 31 |
+
MODULE_PASS("print<regusage>", PhysicalRegisterUsageInfoPrinterPass(errs()))
|
| 32 |
+
MODULE_PASS("shadow-stack-gc-lowering", ShadowStackGCLoweringPass())
|
| 33 |
+
MODULE_PASS("global-merge-func", GlobalMergeFuncPass())
|
| 34 |
+
#undef MODULE_PASS
|
| 35 |
+
|
| 36 |
+
#ifndef FUNCTION_ANALYSIS
|
| 37 |
+
#define FUNCTION_ANALYSIS(NAME, CREATE_PASS)
|
| 38 |
+
#endif
|
| 39 |
+
FUNCTION_ANALYSIS("gc-function", GCFunctionAnalysis())
|
| 40 |
+
FUNCTION_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))
|
| 41 |
+
FUNCTION_ANALYSIS("ssp-layout", SSPLayoutAnalysis())
|
| 42 |
+
FUNCTION_ANALYSIS("target-ir", TargetIRAnalysis(std::move(TM.getTargetIRAnalysis())))
|
| 43 |
+
#undef FUNCTION_ANALYSIS
|
| 44 |
+
|
| 45 |
+
#ifndef FUNCTION_PASS
|
| 46 |
+
#define FUNCTION_PASS(NAME, CREATE_PASS)
|
| 47 |
+
#endif
|
| 48 |
+
FUNCTION_PASS("callbr-prepare", CallBrPreparePass())
|
| 49 |
+
FUNCTION_PASS("cfguard", CFGuardPass())
|
| 50 |
+
FUNCTION_PASS("codegenprepare", CodeGenPreparePass(TM))
|
| 51 |
+
FUNCTION_PASS("consthoist", ConstantHoistingPass())
|
| 52 |
+
FUNCTION_PASS("dwarf-eh-prepare", DwarfEHPreparePass(TM))
|
| 53 |
+
FUNCTION_PASS("ee-instrument", EntryExitInstrumenterPass(false))
|
| 54 |
+
FUNCTION_PASS("expand-large-div-rem", ExpandLargeDivRemPass(TM))
|
| 55 |
+
FUNCTION_PASS("expand-fp", ExpandFpPass(TM))
|
| 56 |
+
FUNCTION_PASS("expand-memcmp", ExpandMemCmpPass(TM))
|
| 57 |
+
FUNCTION_PASS("expand-reductions", ExpandReductionsPass())
|
| 58 |
+
FUNCTION_PASS("gc-lowering", GCLoweringPass())
|
| 59 |
+
FUNCTION_PASS("indirectbr-expand", IndirectBrExpandPass(TM))
|
| 60 |
+
FUNCTION_PASS("interleaved-access", InterleavedAccessPass(TM))
|
| 61 |
+
FUNCTION_PASS("interleaved-load-combine", InterleavedLoadCombinePass(TM))
|
| 62 |
+
FUNCTION_PASS("lower-constant-intrinsics", LowerConstantIntrinsicsPass())
|
| 63 |
+
FUNCTION_PASS("lower-invoke", LowerInvokePass())
|
| 64 |
+
FUNCTION_PASS("mergeicmps", MergeICmpsPass())
|
| 65 |
+
FUNCTION_PASS("partially-inline-libcalls", PartiallyInlineLibCallsPass())
|
| 66 |
+
FUNCTION_PASS("post-inline-ee-instrument", EntryExitInstrumenterPass(true))
|
| 67 |
+
FUNCTION_PASS("replace-with-veclib", ReplaceWithVeclib())
|
| 68 |
+
FUNCTION_PASS("safe-stack", SafeStackPass(TM))
|
| 69 |
+
FUNCTION_PASS("scalarize-masked-mem-intrin", ScalarizeMaskedMemIntrinPass())
|
| 70 |
+
FUNCTION_PASS("select-optimize", SelectOptimizePass(TM))
|
| 71 |
+
FUNCTION_PASS("sjlj-eh-prepare", SjLjEHPreparePass(TM))
|
| 72 |
+
FUNCTION_PASS("stack-protector", StackProtectorPass(TM))
|
| 73 |
+
FUNCTION_PASS("tlshoist", TLSVariableHoistPass())
|
| 74 |
+
FUNCTION_PASS("unreachableblockelim", UnreachableBlockElimPass())
|
| 75 |
+
FUNCTION_PASS("verify", VerifierPass())
|
| 76 |
+
FUNCTION_PASS("wasm-eh-prepare", WasmEHPreparePass())
|
| 77 |
+
FUNCTION_PASS("win-eh-prepare", WinEHPreparePass())
|
| 78 |
+
#undef FUNCTION_PASS
|
| 79 |
+
|
| 80 |
+
#ifndef LOOP_PASS
|
| 81 |
+
#define LOOP_PASS(NAME, CREATE_PASS)
|
| 82 |
+
#endif
|
| 83 |
+
LOOP_PASS("loop-reduce", LoopStrengthReducePass())
|
| 84 |
+
LOOP_PASS("loop-term-fold", LoopTermFoldPass())
|
| 85 |
+
#undef LOOP_PASS
|
| 86 |
+
|
| 87 |
+
#ifndef MACHINE_MODULE_PASS
|
| 88 |
+
#define MACHINE_MODULE_PASS(NAME, CREATE_PASS)
|
| 89 |
+
#endif
|
| 90 |
+
#undef MACHINE_MODULE_PASS
|
| 91 |
+
|
| 92 |
+
#ifndef MACHINE_FUNCTION_ANALYSIS
|
| 93 |
+
#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS)
|
| 94 |
+
#endif
|
| 95 |
+
// LiveVariables currently requires pure SSA form.
|
| 96 |
+
// FIXME: Once TwoAddressInstruction pass no longer uses kill flags,
|
| 97 |
+
// LiveVariables can be removed completely, and LiveIntervals can be directly
|
| 98 |
+
// computed. (We still either need to regenerate kill flags after regalloc, or
|
| 99 |
+
// preferably fix the scavenger to not depend on them).
|
| 100 |
+
MACHINE_FUNCTION_ANALYSIS("edge-bundles", EdgeBundlesAnalysis())
|
| 101 |
+
MACHINE_FUNCTION_ANALYSIS("gisel-value-tracking", GISelValueTrackingAnalysis())
|
| 102 |
+
MACHINE_FUNCTION_ANALYSIS("livedebugvars", LiveDebugVariablesAnalysis())
|
| 103 |
+
MACHINE_FUNCTION_ANALYSIS("live-intervals", LiveIntervalsAnalysis())
|
| 104 |
+
MACHINE_FUNCTION_ANALYSIS("live-reg-matrix", LiveRegMatrixAnalysis())
|
| 105 |
+
MACHINE_FUNCTION_ANALYSIS("live-stacks", LiveStacksAnalysis())
|
| 106 |
+
MACHINE_FUNCTION_ANALYSIS("live-vars", LiveVariablesAnalysis())
|
| 107 |
+
MACHINE_FUNCTION_ANALYSIS("machine-block-freq", MachineBlockFrequencyAnalysis())
|
| 108 |
+
MACHINE_FUNCTION_ANALYSIS("machine-branch-prob",
|
| 109 |
+
MachineBranchProbabilityAnalysis())
|
| 110 |
+
MACHINE_FUNCTION_ANALYSIS("machine-cycles", MachineCycleAnalysis())
|
| 111 |
+
MACHINE_FUNCTION_ANALYSIS("machine-dom-tree", MachineDominatorTreeAnalysis())
|
| 112 |
+
MACHINE_FUNCTION_ANALYSIS("machine-loops", MachineLoopAnalysis())
|
| 113 |
+
MACHINE_FUNCTION_ANALYSIS("machine-opt-remark-emitter",
|
| 114 |
+
MachineOptimizationRemarkEmitterAnalysis())
|
| 115 |
+
MACHINE_FUNCTION_ANALYSIS("machine-post-dom-tree",
|
| 116 |
+
MachinePostDominatorTreeAnalysis())
|
| 117 |
+
MACHINE_FUNCTION_ANALYSIS("machine-trace-metrics", MachineTraceMetricsAnalysis())
|
| 118 |
+
MACHINE_FUNCTION_ANALYSIS("machine-uniformity", MachineUniformityAnalysis())
|
| 119 |
+
MACHINE_FUNCTION_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))
|
| 120 |
+
MACHINE_FUNCTION_ANALYSIS("regalloc-evict", RegAllocEvictionAdvisorAnalysis())
|
| 121 |
+
MACHINE_FUNCTION_ANALYSIS("regalloc-priority", RegAllocPriorityAdvisorAnalysis())
|
| 122 |
+
MACHINE_FUNCTION_ANALYSIS("slot-indexes", SlotIndexesAnalysis())
|
| 123 |
+
MACHINE_FUNCTION_ANALYSIS("spill-code-placement", SpillPlacementAnalysis())
|
| 124 |
+
MACHINE_FUNCTION_ANALYSIS("virtregmap", VirtRegMapAnalysis())
|
| 125 |
+
// MACHINE_FUNCTION_ANALYSIS("lazy-machine-bfi",
|
| 126 |
+
// LazyMachineBlockFrequencyInfoAnalysis())
|
| 127 |
+
// MACHINE_FUNCTION_ANALYSIS("machine-loops", MachineLoopInfoAnalysis())
|
| 128 |
+
// MACHINE_FUNCTION_ANALYSIS("machine-dom-frontier",
|
| 129 |
+
// MachineDominanceFrontierAnalysis())
|
| 130 |
+
// MACHINE_FUNCTION_ANALYSIS("machine-post-dom-tree",
|
| 131 |
+
// MachinePostDominatorTreeAnalysis())
|
| 132 |
+
// MACHINE_FUNCTION_ANALYSIS("machine-region-info",
|
| 133 |
+
// MachineRegionInfoPassAnalysis())
|
| 134 |
+
// MACHINE_FUNCTION_ANALYSIS("reaching-def",
|
| 135 |
+
// ReachingDefAnalysisAnalysis()) MACHINE_FUNCTION_ANALYSIS("gc-analysis",
|
| 136 |
+
// GCMachineCodeAnalysisPass())
|
| 137 |
+
#undef MACHINE_FUNCTION_ANALYSIS
|
| 138 |
+
|
| 139 |
+
#ifndef MACHINE_FUNCTION_PASS
|
| 140 |
+
#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
|
| 141 |
+
#endif
|
| 142 |
+
MACHINE_FUNCTION_PASS("block-placement-stats", MachineBlockPlacementStatsPass())
|
| 143 |
+
MACHINE_FUNCTION_PASS("branch-relaxation", BranchRelaxationPass())
|
| 144 |
+
MACHINE_FUNCTION_PASS("dead-mi-elimination", DeadMachineInstructionElimPass())
|
| 145 |
+
MACHINE_FUNCTION_PASS("detect-dead-lanes", DetectDeadLanesPass())
|
| 146 |
+
MACHINE_FUNCTION_PASS("early-ifcvt", EarlyIfConverterPass())
|
| 147 |
+
MACHINE_FUNCTION_PASS("early-machinelicm", EarlyMachineLICMPass())
|
| 148 |
+
MACHINE_FUNCTION_PASS("early-tailduplication", EarlyTailDuplicatePass())
|
| 149 |
+
MACHINE_FUNCTION_PASS("fentry-insert", FEntryInserterPass())
|
| 150 |
+
MACHINE_FUNCTION_PASS("finalize-isel", FinalizeISelPass())
|
| 151 |
+
MACHINE_FUNCTION_PASS("fixup-statepoint-caller-saved", FixupStatepointCallerSavedPass())
|
| 152 |
+
MACHINE_FUNCTION_PASS("localstackalloc", LocalStackSlotAllocationPass())
|
| 153 |
+
MACHINE_FUNCTION_PASS("machine-cp", MachineCopyPropagationPass())
|
| 154 |
+
MACHINE_FUNCTION_PASS("machine-cse", MachineCSEPass())
|
| 155 |
+
MACHINE_FUNCTION_PASS("machine-latecleanup", MachineLateInstrsCleanupPass())
|
| 156 |
+
MACHINE_FUNCTION_PASS("machine-sanmd", MachineSanitizerBinaryMetadataPass())
|
| 157 |
+
MACHINE_FUNCTION_PASS("machine-scheduler", MachineSchedulerPass(TM))
|
| 158 |
+
MACHINE_FUNCTION_PASS("machinelicm", MachineLICMPass())
|
| 159 |
+
MACHINE_FUNCTION_PASS("no-op-machine-function", NoOpMachineFunctionPass())
|
| 160 |
+
MACHINE_FUNCTION_PASS("opt-phis", OptimizePHIsPass())
|
| 161 |
+
MACHINE_FUNCTION_PASS("patchable-function", PatchableFunctionPass())
|
| 162 |
+
MACHINE_FUNCTION_PASS("peephole-opt", PeepholeOptimizerPass())
|
| 163 |
+
MACHINE_FUNCTION_PASS("phi-node-elimination", PHIEliminationPass())
|
| 164 |
+
MACHINE_FUNCTION_PASS("post-RA-hazard-rec", PostRAHazardRecognizerPass())
|
| 165 |
+
MACHINE_FUNCTION_PASS("post-RA-sched", PostRASchedulerPass(TM))
|
| 166 |
+
MACHINE_FUNCTION_PASS("postmisched", PostMachineSchedulerPass(TM))
|
| 167 |
+
MACHINE_FUNCTION_PASS("post-ra-pseudos", ExpandPostRAPseudosPass())
|
| 168 |
+
MACHINE_FUNCTION_PASS("print", PrintMIRPass())
|
| 169 |
+
MACHINE_FUNCTION_PASS("print<gisel-value-tracking>", GISelValueTrackingPrinterPass(errs()))
|
| 170 |
+
MACHINE_FUNCTION_PASS("print<livedebugvars>", LiveDebugVariablesPrinterPass(errs()))
|
| 171 |
+
MACHINE_FUNCTION_PASS("print<live-intervals>", LiveIntervalsPrinterPass(errs()))
|
| 172 |
+
MACHINE_FUNCTION_PASS("print<live-stacks>", LiveStacksPrinterPass(errs()))
|
| 173 |
+
MACHINE_FUNCTION_PASS("print<live-vars>", LiveVariablesPrinterPass(errs()))
|
| 174 |
+
MACHINE_FUNCTION_PASS("print<machine-block-freq>",
|
| 175 |
+
MachineBlockFrequencyPrinterPass(errs()))
|
| 176 |
+
MACHINE_FUNCTION_PASS("print<machine-branch-prob>",
|
| 177 |
+
MachineBranchProbabilityPrinterPass(errs()))
|
| 178 |
+
MACHINE_FUNCTION_PASS("print<machine-cycles>", MachineCycleInfoPrinterPass(errs()))
|
| 179 |
+
MACHINE_FUNCTION_PASS("print<machine-dom-tree>",
|
| 180 |
+
MachineDominatorTreePrinterPass(errs()))
|
| 181 |
+
MACHINE_FUNCTION_PASS("print<machine-loops>", MachineLoopPrinterPass(errs()))
|
| 182 |
+
MACHINE_FUNCTION_PASS("print<machine-post-dom-tree>",
|
| 183 |
+
MachinePostDominatorTreePrinterPass(errs()))
|
| 184 |
+
MACHINE_FUNCTION_PASS("print<machine-uniformity>",
|
| 185 |
+
MachineUniformityPrinterPass(errs()))
|
| 186 |
+
MACHINE_FUNCTION_PASS("print<slot-indexes>", SlotIndexesPrinterPass(errs()))
|
| 187 |
+
MACHINE_FUNCTION_PASS("print<virtregmap>", VirtRegMapPrinterPass(errs()))
|
| 188 |
+
MACHINE_FUNCTION_PASS("prolog-epilog", PrologEpilogInserterPass())
|
| 189 |
+
MACHINE_FUNCTION_PASS("reg-usage-collector", RegUsageInfoCollectorPass())
|
| 190 |
+
MACHINE_FUNCTION_PASS("reg-usage-propagation", RegUsageInfoPropagationPass())
|
| 191 |
+
MACHINE_FUNCTION_PASS("register-coalescer", RegisterCoalescerPass())
|
| 192 |
+
MACHINE_FUNCTION_PASS("rename-independent-subregs", RenameIndependentSubregsPass())
|
| 193 |
+
MACHINE_FUNCTION_PASS("remove-loads-into-fake-uses", RemoveLoadsIntoFakeUsesPass())
|
| 194 |
+
MACHINE_FUNCTION_PASS("remove-redundant-debug-values", RemoveRedundantDebugValuesPass())
|
| 195 |
+
MACHINE_FUNCTION_PASS("require-all-machine-function-properties",
|
| 196 |
+
RequireAllMachineFunctionPropertiesPass())
|
| 197 |
+
MACHINE_FUNCTION_PASS("shrink-wrap", ShrinkWrapPass())
|
| 198 |
+
MACHINE_FUNCTION_PASS("stack-coloring", StackColoringPass())
|
| 199 |
+
MACHINE_FUNCTION_PASS("stack-frame-layout", StackFrameLayoutAnalysisPass())
|
| 200 |
+
MACHINE_FUNCTION_PASS("stack-slot-coloring", StackSlotColoringPass())
|
| 201 |
+
MACHINE_FUNCTION_PASS("tailduplication", TailDuplicatePass())
|
| 202 |
+
MACHINE_FUNCTION_PASS("trigger-verifier-error", TriggerVerifierErrorPass())
|
| 203 |
+
MACHINE_FUNCTION_PASS("two-address-instruction", TwoAddressInstructionPass())
|
| 204 |
+
MACHINE_FUNCTION_PASS("unreachable-mbb-elimination",
|
| 205 |
+
UnreachableMachineBlockElimPass())
|
| 206 |
+
MACHINE_FUNCTION_PASS("verify", MachineVerifierPass())
|
| 207 |
+
MACHINE_FUNCTION_PASS("verify<machine-trace-metrics>", MachineTraceMetricsVerifierPass())
|
| 208 |
+
MACHINE_FUNCTION_PASS("xray-instrumentation", XRayInstrumentationPass())
|
| 209 |
+
#undef MACHINE_FUNCTION_PASS
|
| 210 |
+
|
| 211 |
+
#ifndef MACHINE_FUNCTION_PASS_WITH_PARAMS
|
| 212 |
+
#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
|
| 213 |
+
PARAMS)
|
| 214 |
+
#endif
|
| 215 |
+
|
| 216 |
+
MACHINE_FUNCTION_PASS_WITH_PARAMS(
|
| 217 |
+
"block-placement", "MachineBlockPlacementPass",
|
| 218 |
+
[](bool AllowTailMerge) {
|
| 219 |
+
// Default is true.
|
| 220 |
+
return MachineBlockPlacementPass(AllowTailMerge);
|
| 221 |
+
},
|
| 222 |
+
parseMachineBlockPlacementPassOptions, "no-tail-merge;tail-merge")
|
| 223 |
+
|
| 224 |
+
MACHINE_FUNCTION_PASS_WITH_PARAMS(
|
| 225 |
+
"branch-folder", "BranchFolderPass",
|
| 226 |
+
[](bool EnableTailMerge) { return BranchFolderPass(EnableTailMerge); },
|
| 227 |
+
[](StringRef Params) {
|
| 228 |
+
return parseSinglePassOption(Params, "enable-tail-merge",
|
| 229 |
+
"BranchFolderPass");
|
| 230 |
+
},
|
| 231 |
+
"enable-tail-merge")
|
| 232 |
+
|
| 233 |
+
MACHINE_FUNCTION_PASS_WITH_PARAMS(
|
| 234 |
+
"live-debug-values", "LiveDebugValuesPass",
|
| 235 |
+
[](bool ShouldEmitDebugEntryValues) {
|
| 236 |
+
return LiveDebugValuesPass(ShouldEmitDebugEntryValues);
|
| 237 |
+
},
|
| 238 |
+
[](StringRef Params) {
|
| 239 |
+
return parseSinglePassOption(Params, "emit-debug-entry-values",
|
| 240 |
+
"LiveDebugValuesPass");
|
| 241 |
+
},
|
| 242 |
+
"emit-debug-entry-values")
|
| 243 |
+
|
| 244 |
+
MACHINE_FUNCTION_PASS_WITH_PARAMS(
|
| 245 |
+
"machine-sink", "MachineSinkingPass",
|
| 246 |
+
[](bool EnableSinkAndFold) {
|
| 247 |
+
return MachineSinkingPass(EnableSinkAndFold);
|
| 248 |
+
},
|
| 249 |
+
parseMachineSinkingPassOptions, "enable-sink-fold")
|
| 250 |
+
|
| 251 |
+
MACHINE_FUNCTION_PASS_WITH_PARAMS(
|
| 252 |
+
"regallocfast", "RegAllocFastPass",
|
| 253 |
+
[](RegAllocFastPass::Options Opts) { return RegAllocFastPass(Opts); },
|
| 254 |
+
[PB = this](StringRef Params) {
|
| 255 |
+
return parseRegAllocFastPassOptions(*PB, Params);
|
| 256 |
+
},
|
| 257 |
+
"filter=reg-filter;no-clear-vregs")
|
| 258 |
+
|
| 259 |
+
// 'all' is the default filter.
|
| 260 |
+
MACHINE_FUNCTION_PASS_WITH_PARAMS(
|
| 261 |
+
"greedy", "RAGreedyPass",
|
| 262 |
+
[](RAGreedyPass::Options Opts) { return RAGreedyPass(Opts); },
|
| 263 |
+
[PB = this](StringRef Params) {
|
| 264 |
+
return parseRegAllocGreedyFilterFunc(*PB, Params);
|
| 265 |
+
}, "reg-filter"
|
| 266 |
+
)
|
| 267 |
+
|
| 268 |
+
MACHINE_FUNCTION_PASS_WITH_PARAMS(
|
| 269 |
+
"virt-reg-rewriter", "VirtRegRewriterPass",
|
| 270 |
+
[](bool ClearVirtRegs) { return VirtRegRewriterPass(ClearVirtRegs); },
|
| 271 |
+
parseVirtRegRewriterPassOptions, "no-clear-vregs;clear-vregs")
|
| 272 |
+
|
| 273 |
+
#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
|
| 274 |
+
|
| 275 |
+
// After a pass is converted to new pass manager, its entry should be moved from
|
| 276 |
+
// dummy table to the normal one. For example, for a machine function pass,
|
| 277 |
+
// DUMMY_MACHINE_FUNCTION_PASS to MACHINE_FUNCTION_PASS.
|
| 278 |
+
|
| 279 |
+
#ifndef DUMMY_FUNCTION_PASS
|
| 280 |
+
#define DUMMY_FUNCTION_PASS(NAME, PASS_NAME)
|
| 281 |
+
#endif
|
| 282 |
+
#undef DUMMY_FUNCTION_PASS
|
| 283 |
+
|
| 284 |
+
#ifndef DUMMY_MACHINE_MODULE_PASS
|
| 285 |
+
#define DUMMY_MACHINE_MODULE_PASS(NAME, PASS_NAME)
|
| 286 |
+
#endif
|
| 287 |
+
DUMMY_MACHINE_MODULE_PASS("machine-outliner", MachineOutlinerPass)
|
| 288 |
+
DUMMY_MACHINE_MODULE_PASS("static-data-annotator", StaticDataAnnotator)
|
| 289 |
+
DUMMY_MACHINE_MODULE_PASS("pseudo-probe-inserter", PseudoProbeInserterPass)
|
| 290 |
+
DUMMY_MACHINE_MODULE_PASS("mir-debugify", DebugifyMachineModule)
|
| 291 |
+
DUMMY_MACHINE_MODULE_PASS("mir-check-debugify", CheckDebugMachineModulePass)
|
| 292 |
+
DUMMY_MACHINE_MODULE_PASS("mir-strip-debug", StripDebugMachineModulePass)
|
| 293 |
+
#undef DUMMY_MACHINE_MODULE_PASS
|
| 294 |
+
|
| 295 |
+
#ifndef DUMMY_MACHINE_FUNCTION_PASS
|
| 296 |
+
#define DUMMY_MACHINE_FUNCTION_PASS(NAME, PASS_NAME)
|
| 297 |
+
#endif
|
| 298 |
+
DUMMY_MACHINE_FUNCTION_PASS("bbsections-prepare", BasicBlockSectionsPass)
|
| 299 |
+
DUMMY_MACHINE_FUNCTION_PASS("bbsections-profile-reader", BasicBlockSectionsProfileReaderPass)
|
| 300 |
+
DUMMY_MACHINE_FUNCTION_PASS("break-false-deps", BreakFalseDepsPass)
|
| 301 |
+
DUMMY_MACHINE_FUNCTION_PASS("cfguard-longjmp", CFGuardLongjmpPass)
|
| 302 |
+
DUMMY_MACHINE_FUNCTION_PASS("cfi-fixup", CFIFixupPass)
|
| 303 |
+
DUMMY_MACHINE_FUNCTION_PASS("cfi-instr-inserter", CFIInstrInserterPass)
|
| 304 |
+
DUMMY_MACHINE_FUNCTION_PASS("dot-machine-cfg", MachineCFGPrinter)
|
| 305 |
+
DUMMY_MACHINE_FUNCTION_PASS("fs-profile-loader", MIRProfileLoaderNewPass)
|
| 306 |
+
DUMMY_MACHINE_FUNCTION_PASS("funclet-layout", FuncletLayoutPass)
|
| 307 |
+
DUMMY_MACHINE_FUNCTION_PASS("gc-empty-basic-blocks", GCEmptyBasicBlocksPass)
|
| 308 |
+
DUMMY_MACHINE_FUNCTION_PASS("implicit-null-checks", ImplicitNullChecksPass)
|
| 309 |
+
DUMMY_MACHINE_FUNCTION_PASS("init-undef-pass", InitUndefPass)
|
| 310 |
+
DUMMY_MACHINE_FUNCTION_PASS("instruction-select", InstructionSelectPass)
|
| 311 |
+
DUMMY_MACHINE_FUNCTION_PASS("irtranslator", IRTranslatorPass)
|
| 312 |
+
DUMMY_MACHINE_FUNCTION_PASS("kcfi", MachineKCFIPass)
|
| 313 |
+
DUMMY_MACHINE_FUNCTION_PASS("legalizer", LegalizerPass)
|
| 314 |
+
DUMMY_MACHINE_FUNCTION_PASS("lrshrink", LiveRangeShrinkPass)
|
| 315 |
+
DUMMY_MACHINE_FUNCTION_PASS("machine-combiner", MachineCombinerPass)
|
| 316 |
+
DUMMY_MACHINE_FUNCTION_PASS("static-data-splitter", StaticDataSplitter)
|
| 317 |
+
DUMMY_MACHINE_FUNCTION_PASS("machine-function-splitter", MachineFunctionSplitterPass)
|
| 318 |
+
DUMMY_MACHINE_FUNCTION_PASS("machineinstr-printer", MachineFunctionPrinterPass)
|
| 319 |
+
DUMMY_MACHINE_FUNCTION_PASS("mirfs-discriminators", MIRAddFSDiscriminatorsPass)
|
| 320 |
+
DUMMY_MACHINE_FUNCTION_PASS("postra-machine-sink", PostRAMachineSinkingPass)
|
| 321 |
+
DUMMY_MACHINE_FUNCTION_PASS("processimpdefs", ProcessImplicitDefsPass)
|
| 322 |
+
DUMMY_MACHINE_FUNCTION_PASS("prologepilog-code", PrologEpilogCodeInserterPass)
|
| 323 |
+
DUMMY_MACHINE_FUNCTION_PASS("ra-basic", RABasicPass)
|
| 324 |
+
DUMMY_MACHINE_FUNCTION_PASS("ra-pbqp", RAPBQPPass)
|
| 325 |
+
DUMMY_MACHINE_FUNCTION_PASS("regalloc", RegAllocPass)
|
| 326 |
+
DUMMY_MACHINE_FUNCTION_PASS("regallocscoringpass", RegAllocScoringPass)
|
| 327 |
+
DUMMY_MACHINE_FUNCTION_PASS("regbankselect", RegBankSelectPass)
|
| 328 |
+
DUMMY_MACHINE_FUNCTION_PASS("reset-machine-function", ResetMachineFunctionPass)
|
| 329 |
+
DUMMY_MACHINE_FUNCTION_PASS("stackmap-liveness", StackMapLivenessPass)
|
| 330 |
+
DUMMY_MACHINE_FUNCTION_PASS("unpack-mi-bundles", UnpackMachineBundlesPass)
|
| 331 |
+
#undef DUMMY_MACHINE_FUNCTION_PASS
|
deps/exla/cache/xla_extension/include/llvm/Passes/OptimizationLevel.h
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-------- LLVM-provided High-Level Optimization levels -*- C++ -*------===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
/// \file
|
| 9 |
+
///
|
| 10 |
+
/// This header enumerates the LLVM-provided high-level optimization levels.
|
| 11 |
+
/// Each level has a specific goal and rationale.
|
| 12 |
+
///
|
| 13 |
+
//===----------------------------------------------------------------------===//
|
| 14 |
+
|
| 15 |
+
#ifndef LLVM_PASSES_OPTIMIZATIONLEVEL_H
|
| 16 |
+
#define LLVM_PASSES_OPTIMIZATIONLEVEL_H
|
| 17 |
+
|
| 18 |
+
#include <assert.h>
|
| 19 |
+
|
| 20 |
+
namespace llvm {
|
| 21 |
+
|
| 22 |
+
class OptimizationLevel final {
|
| 23 |
+
unsigned SpeedLevel = 2;
|
| 24 |
+
unsigned SizeLevel = 0;
|
| 25 |
+
OptimizationLevel(unsigned SpeedLevel, unsigned SizeLevel)
|
| 26 |
+
: SpeedLevel(SpeedLevel), SizeLevel(SizeLevel) {
|
| 27 |
+
// Check that only valid combinations are passed.
|
| 28 |
+
assert(SpeedLevel <= 3 &&
|
| 29 |
+
"Optimization level for speed should be 0, 1, 2, or 3");
|
| 30 |
+
assert(SizeLevel <= 2 &&
|
| 31 |
+
"Optimization level for size should be 0, 1, or 2");
|
| 32 |
+
assert((SizeLevel == 0 || SpeedLevel == 2) &&
|
| 33 |
+
"Optimize for size should be encoded with speedup level == 2");
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
public:
|
| 37 |
+
OptimizationLevel() = default;
|
| 38 |
+
/// Disable as many optimizations as possible. This doesn't completely
|
| 39 |
+
/// disable the optimizer in all cases, for example always_inline functions
|
| 40 |
+
/// can be required to be inlined for correctness.
|
| 41 |
+
static const OptimizationLevel O0;
|
| 42 |
+
|
| 43 |
+
/// Optimize quickly without destroying debuggability.
|
| 44 |
+
///
|
| 45 |
+
/// This level is tuned to produce a result from the optimizer as quickly
|
| 46 |
+
/// as possible and to avoid destroying debuggability. This tends to result
|
| 47 |
+
/// in a very good development mode where the compiled code will be
|
| 48 |
+
/// immediately executed as part of testing. As a consequence, where
|
| 49 |
+
/// possible, we would like to produce efficient-to-execute code, but not
|
| 50 |
+
/// if it significantly slows down compilation or would prevent even basic
|
| 51 |
+
/// debugging of the resulting binary.
|
| 52 |
+
///
|
| 53 |
+
/// As an example, complex loop transformations such as versioning,
|
| 54 |
+
/// vectorization, or fusion don't make sense here due to the degree to
|
| 55 |
+
/// which the executed code differs from the source code, and the compile
|
| 56 |
+
/// time cost.
|
| 57 |
+
static const OptimizationLevel O1;
|
| 58 |
+
/// Optimize for fast execution as much as possible without triggering
|
| 59 |
+
/// significant incremental compile time or code size growth.
|
| 60 |
+
///
|
| 61 |
+
/// The key idea is that optimizations at this level should "pay for
|
| 62 |
+
/// themselves". So if an optimization increases compile time by 5% or
|
| 63 |
+
/// increases code size by 5% for a particular benchmark, that benchmark
|
| 64 |
+
/// should also be one which sees a 5% runtime improvement. If the compile
|
| 65 |
+
/// time or code size penalties happen on average across a diverse range of
|
| 66 |
+
/// LLVM users' benchmarks, then the improvements should as well.
|
| 67 |
+
///
|
| 68 |
+
/// And no matter what, the compile time needs to not grow superlinearly
|
| 69 |
+
/// with the size of input to LLVM so that users can control the runtime of
|
| 70 |
+
/// the optimizer in this mode.
|
| 71 |
+
///
|
| 72 |
+
/// This is expected to be a good default optimization level for the vast
|
| 73 |
+
/// majority of users.
|
| 74 |
+
static const OptimizationLevel O2;
|
| 75 |
+
/// Optimize for fast execution as much as possible.
|
| 76 |
+
///
|
| 77 |
+
/// This mode is significantly more aggressive in trading off compile time
|
| 78 |
+
/// and code size to get execution time improvements. The core idea is that
|
| 79 |
+
/// this mode should include any optimization that helps execution time on
|
| 80 |
+
/// balance across a diverse collection of benchmarks, even if it increases
|
| 81 |
+
/// code size or compile time for some benchmarks without corresponding
|
| 82 |
+
/// improvements to execution time.
|
| 83 |
+
///
|
| 84 |
+
/// Despite being willing to trade more compile time off to get improved
|
| 85 |
+
/// execution time, this mode still tries to avoid superlinear growth in
|
| 86 |
+
/// order to make even significantly slower compile times at least scale
|
| 87 |
+
/// reasonably. This does not preclude very substantial constant factor
|
| 88 |
+
/// costs though.
|
| 89 |
+
static const OptimizationLevel O3;
|
| 90 |
+
/// Similar to \c O2 but tries to optimize for small code size instead of
|
| 91 |
+
/// fast execution without triggering significant incremental execution
|
| 92 |
+
/// time slowdowns.
|
| 93 |
+
///
|
| 94 |
+
/// The logic here is exactly the same as \c O2, but with code size and
|
| 95 |
+
/// execution time metrics swapped.
|
| 96 |
+
///
|
| 97 |
+
/// A consequence of the different core goal is that this should in general
|
| 98 |
+
/// produce substantially smaller executables that still run in
|
| 99 |
+
/// a reasonable amount of time.
|
| 100 |
+
static const OptimizationLevel Os;
|
| 101 |
+
/// A very specialized mode that will optimize for code size at any and all
|
| 102 |
+
/// costs.
|
| 103 |
+
///
|
| 104 |
+
/// This is useful primarily when there are absolute size limitations and
|
| 105 |
+
/// any effort taken to reduce the size is worth it regardless of the
|
| 106 |
+
/// execution time impact. You should expect this level to produce rather
|
| 107 |
+
/// slow, but very small, code.
|
| 108 |
+
static const OptimizationLevel Oz;
|
| 109 |
+
|
| 110 |
+
bool isOptimizingForSpeed() const { return SizeLevel == 0 && SpeedLevel > 0; }
|
| 111 |
+
|
| 112 |
+
bool isOptimizingForSize() const { return SizeLevel > 0; }
|
| 113 |
+
|
| 114 |
+
bool operator==(const OptimizationLevel &Other) const {
|
| 115 |
+
return SizeLevel == Other.SizeLevel && SpeedLevel == Other.SpeedLevel;
|
| 116 |
+
}
|
| 117 |
+
bool operator!=(const OptimizationLevel &Other) const {
|
| 118 |
+
return SizeLevel != Other.SizeLevel || SpeedLevel != Other.SpeedLevel;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
unsigned getSpeedupLevel() const { return SpeedLevel; }
|
| 122 |
+
|
| 123 |
+
unsigned getSizeLevel() const { return SizeLevel; }
|
| 124 |
+
};
|
| 125 |
+
} // namespace llvm
|
| 126 |
+
|
| 127 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Passes/PassBuilder.h
ADDED
|
@@ -0,0 +1,985 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- Parsing, selection, and construction of pass pipelines --*- C++ -*--===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
/// \file
|
| 9 |
+
///
|
| 10 |
+
/// Interfaces for registering analysis passes, producing common pass manager
|
| 11 |
+
/// configurations, and parsing of pass pipelines.
|
| 12 |
+
///
|
| 13 |
+
//===----------------------------------------------------------------------===//
|
| 14 |
+
|
| 15 |
+
#ifndef LLVM_PASSES_PASSBUILDER_H
|
| 16 |
+
#define LLVM_PASSES_PASSBUILDER_H
|
| 17 |
+
|
| 18 |
+
#include "llvm/Analysis/CGSCCPassManager.h"
|
| 19 |
+
#include "llvm/CodeGen/MachinePassManager.h"
|
| 20 |
+
#include "llvm/CodeGen/RegAllocCommon.h"
|
| 21 |
+
#include "llvm/IR/PassManager.h"
|
| 22 |
+
#include "llvm/Passes/OptimizationLevel.h"
|
| 23 |
+
#include "llvm/Support/Error.h"
|
| 24 |
+
#include "llvm/Support/PGOOptions.h"
|
| 25 |
+
#include "llvm/Support/raw_ostream.h"
|
| 26 |
+
#include "llvm/Transforms/IPO/Inliner.h"
|
| 27 |
+
#include "llvm/Transforms/IPO/ModuleInliner.h"
|
| 28 |
+
#include "llvm/Transforms/Scalar/LoopPassManager.h"
|
| 29 |
+
#include <optional>
|
| 30 |
+
#include <vector>
|
| 31 |
+
|
| 32 |
+
namespace llvm {
|
| 33 |
+
class StringRef;
|
| 34 |
+
class AAManager;
|
| 35 |
+
class TargetMachine;
|
| 36 |
+
class ModuleSummaryIndex;
|
| 37 |
+
template <typename T> class IntrusiveRefCntPtr;
|
| 38 |
+
namespace vfs {
|
| 39 |
+
class FileSystem;
|
| 40 |
+
} // namespace vfs
|
| 41 |
+
|
| 42 |
+
/// Tunable parameters for passes in the default pipelines.
|
| 43 |
+
class PipelineTuningOptions {
|
| 44 |
+
public:
|
| 45 |
+
/// Constructor sets pipeline tuning defaults based on cl::opts. Each option
|
| 46 |
+
/// can be set in the PassBuilder when using a LLVM as a library.
|
| 47 |
+
PipelineTuningOptions();
|
| 48 |
+
|
| 49 |
+
/// Tuning option to set loop interleaving on/off, set based on opt level.
|
| 50 |
+
bool LoopInterleaving;
|
| 51 |
+
|
| 52 |
+
/// Tuning option to enable/disable loop vectorization, set based on opt
|
| 53 |
+
/// level.
|
| 54 |
+
bool LoopVectorization;
|
| 55 |
+
|
| 56 |
+
/// Tuning option to enable/disable slp loop vectorization, set based on opt
|
| 57 |
+
/// level.
|
| 58 |
+
bool SLPVectorization;
|
| 59 |
+
|
| 60 |
+
/// Tuning option to enable/disable loop unrolling. Its default value is true.
|
| 61 |
+
bool LoopUnrolling;
|
| 62 |
+
|
| 63 |
+
/// Tuning option to enable/disable loop interchange. Its default value is
|
| 64 |
+
/// false.
|
| 65 |
+
bool LoopInterchange;
|
| 66 |
+
|
| 67 |
+
/// Tuning option to forget all SCEV loops in LoopUnroll. Its default value
|
| 68 |
+
/// is that of the flag: `-forget-scev-loop-unroll`.
|
| 69 |
+
bool ForgetAllSCEVInLoopUnroll;
|
| 70 |
+
|
| 71 |
+
/// Tuning option to cap the number of calls to retrive clobbering accesses in
|
| 72 |
+
/// MemorySSA, in LICM.
|
| 73 |
+
unsigned LicmMssaOptCap;
|
| 74 |
+
|
| 75 |
+
/// Tuning option to disable promotion to scalars in LICM with MemorySSA, if
|
| 76 |
+
/// the number of access is too large.
|
| 77 |
+
unsigned LicmMssaNoAccForPromotionCap;
|
| 78 |
+
|
| 79 |
+
/// Tuning option to enable/disable call graph profile. Its default value is
|
| 80 |
+
/// that of the flag: `-enable-npm-call-graph-profile`.
|
| 81 |
+
bool CallGraphProfile;
|
| 82 |
+
|
| 83 |
+
// Add LTO pipeline tuning option to enable the unified LTO pipeline.
|
| 84 |
+
bool UnifiedLTO;
|
| 85 |
+
|
| 86 |
+
/// Tuning option to enable/disable function merging. Its default value is
|
| 87 |
+
/// false.
|
| 88 |
+
bool MergeFunctions;
|
| 89 |
+
|
| 90 |
+
/// Tuning option to override the default inliner threshold.
|
| 91 |
+
int InlinerThreshold;
|
| 92 |
+
|
| 93 |
+
// Experimental option to eagerly invalidate more analyses. This has the
|
| 94 |
+
// potential to decrease max memory usage in exchange for more compile time.
|
| 95 |
+
// This may affect codegen due to either passes using analyses only when
|
| 96 |
+
// cached, or invalidating and recalculating an analysis that was
|
| 97 |
+
// stale/imprecise but still valid. Currently this invalidates all function
|
| 98 |
+
// analyses after various module->function or cgscc->function adaptors in the
|
| 99 |
+
// default pipelines.
|
| 100 |
+
bool EagerlyInvalidateAnalyses;
|
| 101 |
+
};
|
| 102 |
+
|
| 103 |
+
/// This class provides access to building LLVM's passes.
|
| 104 |
+
///
|
| 105 |
+
/// Its members provide the baseline state available to passes during their
|
| 106 |
+
/// construction. The \c PassRegistry.def file specifies how to construct all
|
| 107 |
+
/// of the built-in passes, and those may reference these members during
|
| 108 |
+
/// construction.
|
| 109 |
+
class PassBuilder {
|
| 110 |
+
TargetMachine *TM;
|
| 111 |
+
PipelineTuningOptions PTO;
|
| 112 |
+
std::optional<PGOOptions> PGOOpt;
|
| 113 |
+
PassInstrumentationCallbacks *PIC;
|
| 114 |
+
|
| 115 |
+
public:
|
| 116 |
+
/// A struct to capture parsed pass pipeline names.
|
| 117 |
+
///
|
| 118 |
+
/// A pipeline is defined as a series of names, each of which may in itself
|
| 119 |
+
/// recursively contain a nested pipeline. A name is either the name of a pass
|
| 120 |
+
/// (e.g. "instcombine") or the name of a pipeline type (e.g. "cgscc"). If the
|
| 121 |
+
/// name is the name of a pass, the InnerPipeline is empty, since passes
|
| 122 |
+
/// cannot contain inner pipelines. See parsePassPipeline() for a more
|
| 123 |
+
/// detailed description of the textual pipeline format.
|
| 124 |
+
struct PipelineElement {
|
| 125 |
+
StringRef Name;
|
| 126 |
+
std::vector<PipelineElement> InnerPipeline;
|
| 127 |
+
};
|
| 128 |
+
|
| 129 |
+
explicit PassBuilder(TargetMachine *TM = nullptr,
|
| 130 |
+
PipelineTuningOptions PTO = PipelineTuningOptions(),
|
| 131 |
+
std::optional<PGOOptions> PGOOpt = std::nullopt,
|
| 132 |
+
PassInstrumentationCallbacks *PIC = nullptr);
|
| 133 |
+
|
| 134 |
+
/// Cross register the analysis managers through their proxies.
|
| 135 |
+
///
|
| 136 |
+
/// This is an interface that can be used to cross register each
|
| 137 |
+
/// AnalysisManager with all the others analysis managers.
|
| 138 |
+
void crossRegisterProxies(LoopAnalysisManager &LAM,
|
| 139 |
+
FunctionAnalysisManager &FAM,
|
| 140 |
+
CGSCCAnalysisManager &CGAM,
|
| 141 |
+
ModuleAnalysisManager &MAM,
|
| 142 |
+
MachineFunctionAnalysisManager *MFAM = nullptr);
|
| 143 |
+
|
| 144 |
+
/// Registers all available module analysis passes.
|
| 145 |
+
///
|
| 146 |
+
/// This is an interface that can be used to populate a \c
|
| 147 |
+
/// ModuleAnalysisManager with all registered module analyses. Callers can
|
| 148 |
+
/// still manually register any additional analyses. Callers can also
|
| 149 |
+
/// pre-register analyses and this will not override those.
|
| 150 |
+
void registerModuleAnalyses(ModuleAnalysisManager &MAM);
|
| 151 |
+
|
| 152 |
+
/// Registers all available CGSCC analysis passes.
|
| 153 |
+
///
|
| 154 |
+
/// This is an interface that can be used to populate a \c CGSCCAnalysisManager
|
| 155 |
+
/// with all registered CGSCC analyses. Callers can still manually register any
|
| 156 |
+
/// additional analyses. Callers can also pre-register analyses and this will
|
| 157 |
+
/// not override those.
|
| 158 |
+
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM);
|
| 159 |
+
|
| 160 |
+
/// Registers all available function analysis passes.
|
| 161 |
+
///
|
| 162 |
+
/// This is an interface that can be used to populate a \c
|
| 163 |
+
/// FunctionAnalysisManager with all registered function analyses. Callers can
|
| 164 |
+
/// still manually register any additional analyses. Callers can also
|
| 165 |
+
/// pre-register analyses and this will not override those.
|
| 166 |
+
void registerFunctionAnalyses(FunctionAnalysisManager &FAM);
|
| 167 |
+
|
| 168 |
+
/// Registers all available loop analysis passes.
|
| 169 |
+
///
|
| 170 |
+
/// This is an interface that can be used to populate a \c LoopAnalysisManager
|
| 171 |
+
/// with all registered loop analyses. Callers can still manually register any
|
| 172 |
+
/// additional analyses.
|
| 173 |
+
void registerLoopAnalyses(LoopAnalysisManager &LAM);
|
| 174 |
+
|
| 175 |
+
/// Registers all available machine function analysis passes.
|
| 176 |
+
///
|
| 177 |
+
/// This is an interface that can be used to populate a \c
|
| 178 |
+
/// MachineFunctionAnalysisManager with all registered function analyses.
|
| 179 |
+
/// Callers can still manually register any additional analyses. Callers can
|
| 180 |
+
/// also pre-register analyses and this will not override those.
|
| 181 |
+
void registerMachineFunctionAnalyses(MachineFunctionAnalysisManager &MFAM);
|
| 182 |
+
|
| 183 |
+
/// Construct the core LLVM function canonicalization and simplification
|
| 184 |
+
/// pipeline.
|
| 185 |
+
///
|
| 186 |
+
/// This is a long pipeline and uses most of the per-function optimization
|
| 187 |
+
/// passes in LLVM to canonicalize and simplify the IR. It is suitable to run
|
| 188 |
+
/// repeatedly over the IR and is not expected to destroy important
|
| 189 |
+
/// information about the semantics of the IR.
|
| 190 |
+
///
|
| 191 |
+
/// Note that \p Level cannot be `O0` here. The pipelines produced are
|
| 192 |
+
/// only intended for use when attempting to optimize code. If frontends
|
| 193 |
+
/// require some transformations for semantic reasons, they should explicitly
|
| 194 |
+
/// build them.
|
| 195 |
+
///
|
| 196 |
+
/// \p Phase indicates the current ThinLTO phase.
|
| 197 |
+
FunctionPassManager
|
| 198 |
+
buildFunctionSimplificationPipeline(OptimizationLevel Level,
|
| 199 |
+
ThinOrFullLTOPhase Phase);
|
| 200 |
+
|
| 201 |
+
/// Construct the core LLVM module canonicalization and simplification
|
| 202 |
+
/// pipeline.
|
| 203 |
+
///
|
| 204 |
+
/// This pipeline focuses on canonicalizing and simplifying the entire module
|
| 205 |
+
/// of IR. Much like the function simplification pipeline above, it is
|
| 206 |
+
/// suitable to run repeatedly over the IR and is not expected to destroy
|
| 207 |
+
/// important information. It does, however, perform inlining and other
|
| 208 |
+
/// heuristic based simplifications that are not strictly reversible.
|
| 209 |
+
///
|
| 210 |
+
/// Note that \p Level cannot be `O0` here. The pipelines produced are
|
| 211 |
+
/// only intended for use when attempting to optimize code. If frontends
|
| 212 |
+
/// require some transformations for semantic reasons, they should explicitly
|
| 213 |
+
/// build them.
|
| 214 |
+
///
|
| 215 |
+
/// \p Phase indicates the current ThinLTO phase.
|
| 216 |
+
ModulePassManager buildModuleSimplificationPipeline(OptimizationLevel Level,
|
| 217 |
+
ThinOrFullLTOPhase Phase);
|
| 218 |
+
|
| 219 |
+
/// Construct the module pipeline that performs inlining as well as
|
| 220 |
+
/// the inlining-driven cleanups.
|
| 221 |
+
ModuleInlinerWrapperPass buildInlinerPipeline(OptimizationLevel Level,
|
| 222 |
+
ThinOrFullLTOPhase Phase);
|
| 223 |
+
|
| 224 |
+
/// Construct the module pipeline that performs inlining with
|
| 225 |
+
/// module inliner pass.
|
| 226 |
+
ModulePassManager buildModuleInlinerPipeline(OptimizationLevel Level,
|
| 227 |
+
ThinOrFullLTOPhase Phase);
|
| 228 |
+
|
| 229 |
+
/// Construct the core LLVM module optimization pipeline.
|
| 230 |
+
///
|
| 231 |
+
/// This pipeline focuses on optimizing the execution speed of the IR. It
|
| 232 |
+
/// uses cost modeling and thresholds to balance code growth against runtime
|
| 233 |
+
/// improvements. It includes vectorization and other information destroying
|
| 234 |
+
/// transformations. It also cannot generally be run repeatedly on a module
|
| 235 |
+
/// without potentially seriously regressing either runtime performance of
|
| 236 |
+
/// the code or serious code size growth.
|
| 237 |
+
///
|
| 238 |
+
/// Note that \p Level cannot be `O0` here. The pipelines produced are
|
| 239 |
+
/// only intended for use when attempting to optimize code. If frontends
|
| 240 |
+
/// require some transformations for semantic reasons, they should explicitly
|
| 241 |
+
/// build them.
|
| 242 |
+
ModulePassManager
|
| 243 |
+
buildModuleOptimizationPipeline(OptimizationLevel Level,
|
| 244 |
+
ThinOrFullLTOPhase LTOPhase);
|
| 245 |
+
|
| 246 |
+
/// Build a per-module default optimization pipeline.
|
| 247 |
+
///
|
| 248 |
+
/// This provides a good default optimization pipeline for per-module
|
| 249 |
+
/// optimization and code generation without any link-time optimization. It
|
| 250 |
+
/// typically correspond to frontend "-O[123]" options for optimization
|
| 251 |
+
/// levels \c O1, \c O2 and \c O3 resp.
|
| 252 |
+
ModulePassManager buildPerModuleDefaultPipeline(
|
| 253 |
+
OptimizationLevel Level,
|
| 254 |
+
ThinOrFullLTOPhase Phase = ThinOrFullLTOPhase::None);
|
| 255 |
+
|
| 256 |
+
/// Build a fat object default optimization pipeline.
|
| 257 |
+
///
|
| 258 |
+
/// This builds a pipeline that runs the LTO/ThinLTO pre-link pipeline, and
|
| 259 |
+
/// emits a section containing the pre-link bitcode along side the object code
|
| 260 |
+
/// generated in non-LTO compilation.
|
| 261 |
+
ModulePassManager buildFatLTODefaultPipeline(OptimizationLevel Level,
|
| 262 |
+
bool ThinLTO, bool EmitSummary);
|
| 263 |
+
|
| 264 |
+
/// Build a pre-link, ThinLTO-targeting default optimization pipeline to
|
| 265 |
+
/// a pass manager.
|
| 266 |
+
///
|
| 267 |
+
/// This adds the pre-link optimizations tuned to prepare a module for
|
| 268 |
+
/// a ThinLTO run. It works to minimize the IR which needs to be analyzed
|
| 269 |
+
/// without making irreversible decisions which could be made better during
|
| 270 |
+
/// the LTO run.
|
| 271 |
+
ModulePassManager buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level);
|
| 272 |
+
|
| 273 |
+
/// Build a ThinLTO default optimization pipeline to a pass manager.
|
| 274 |
+
///
|
| 275 |
+
/// This provides a good default optimization pipeline for link-time
|
| 276 |
+
/// optimization and code generation. It is particularly tuned to fit well
|
| 277 |
+
/// when IR coming into the LTO phase was first run through \c
|
| 278 |
+
/// buildThinLTOPreLinkDefaultPipeline, and the two coordinate closely.
|
| 279 |
+
ModulePassManager
|
| 280 |
+
buildThinLTODefaultPipeline(OptimizationLevel Level,
|
| 281 |
+
const ModuleSummaryIndex *ImportSummary);
|
| 282 |
+
|
| 283 |
+
/// Build a pre-link, LTO-targeting default optimization pipeline to a pass
|
| 284 |
+
/// manager.
|
| 285 |
+
///
|
| 286 |
+
/// This adds the pre-link optimizations tuned to work well with a later LTO
|
| 287 |
+
/// run. It works to minimize the IR which needs to be analyzed without
|
| 288 |
+
/// making irreversible decisions which could be made better during the LTO
|
| 289 |
+
/// run.
|
| 290 |
+
ModulePassManager buildLTOPreLinkDefaultPipeline(OptimizationLevel Level);
|
| 291 |
+
|
| 292 |
+
/// Build an LTO default optimization pipeline to a pass manager.
|
| 293 |
+
///
|
| 294 |
+
/// This provides a good default optimization pipeline for link-time
|
| 295 |
+
/// optimization and code generation. It is particularly tuned to fit well
|
| 296 |
+
/// when IR coming into the LTO phase was first run through \c
|
| 297 |
+
/// buildLTOPreLinkDefaultPipeline, and the two coordinate closely.
|
| 298 |
+
ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level,
|
| 299 |
+
ModuleSummaryIndex *ExportSummary);
|
| 300 |
+
|
| 301 |
+
/// Build an O0 pipeline with the minimal semantically required passes.
|
| 302 |
+
///
|
| 303 |
+
/// This should only be used for non-LTO and LTO pre-link pipelines.
|
| 304 |
+
ModulePassManager
|
| 305 |
+
buildO0DefaultPipeline(OptimizationLevel Level,
|
| 306 |
+
ThinOrFullLTOPhase Phase = ThinOrFullLTOPhase::None);
|
| 307 |
+
|
| 308 |
+
/// Build the default `AAManager` with the default alias analysis pipeline
|
| 309 |
+
/// registered.
|
| 310 |
+
///
|
| 311 |
+
/// This also adds target-specific alias analyses registered via
|
| 312 |
+
/// TargetMachine::registerDefaultAliasAnalyses().
|
| 313 |
+
AAManager buildDefaultAAPipeline();
|
| 314 |
+
|
| 315 |
+
/// Parse a textual pass pipeline description into a \c
|
| 316 |
+
/// ModulePassManager.
|
| 317 |
+
///
|
| 318 |
+
/// The format of the textual pass pipeline description looks something like:
|
| 319 |
+
///
|
| 320 |
+
/// module(function(instcombine,sroa),dce,cgscc(inliner,function(...)),...)
|
| 321 |
+
///
|
| 322 |
+
/// Pass managers have ()s describing the nest structure of passes. All passes
|
| 323 |
+
/// are comma separated. As a special shortcut, if the very first pass is not
|
| 324 |
+
/// a module pass (as a module pass manager is), this will automatically form
|
| 325 |
+
/// the shortest stack of pass managers that allow inserting that first pass.
|
| 326 |
+
/// So, assuming function passes 'fpassN', CGSCC passes 'cgpassN', and loop
|
| 327 |
+
/// passes 'lpassN', all of these are valid:
|
| 328 |
+
///
|
| 329 |
+
/// fpass1,fpass2,fpass3
|
| 330 |
+
/// cgpass1,cgpass2,cgpass3
|
| 331 |
+
/// lpass1,lpass2,lpass3
|
| 332 |
+
///
|
| 333 |
+
/// And they are equivalent to the following (resp.):
|
| 334 |
+
///
|
| 335 |
+
/// module(function(fpass1,fpass2,fpass3))
|
| 336 |
+
/// module(cgscc(cgpass1,cgpass2,cgpass3))
|
| 337 |
+
/// module(function(loop(lpass1,lpass2,lpass3)))
|
| 338 |
+
///
|
| 339 |
+
/// This shortcut is especially useful for debugging and testing small pass
|
| 340 |
+
/// combinations.
|
| 341 |
+
///
|
| 342 |
+
/// The sequence of passes aren't necessarily the exact same kind of pass.
|
| 343 |
+
/// You can mix different levels implicitly if adaptor passes are defined to
|
| 344 |
+
/// make them work. For example,
|
| 345 |
+
///
|
| 346 |
+
/// mpass1,fpass1,fpass2,mpass2,lpass1
|
| 347 |
+
///
|
| 348 |
+
/// This pipeline uses only one pass manager: the top-level module manager.
|
| 349 |
+
/// fpass1,fpass2 and lpass1 are added into the top-level module manager
|
| 350 |
+
/// using only adaptor passes. No nested function/loop pass managers are
|
| 351 |
+
/// added. The purpose is to allow easy pass testing when the user
|
| 352 |
+
/// specifically want the pass to run under a adaptor directly. This is
|
| 353 |
+
/// preferred when a pipeline is largely of one type, but one or just a few
|
| 354 |
+
/// passes are of different types(See PassBuilder.cpp for examples).
|
| 355 |
+
Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText);
|
| 356 |
+
|
| 357 |
+
/// {{@ Parse a textual pass pipeline description into a specific PassManager
|
| 358 |
+
///
|
| 359 |
+
/// Automatic deduction of an appropriate pass manager stack is not supported.
|
| 360 |
+
/// For example, to insert a loop pass 'lpass' into a FunctionPassManager,
|
| 361 |
+
/// this is the valid pipeline text:
|
| 362 |
+
///
|
| 363 |
+
/// function(lpass)
|
| 364 |
+
Error parsePassPipeline(CGSCCPassManager &CGPM, StringRef PipelineText);
|
| 365 |
+
Error parsePassPipeline(FunctionPassManager &FPM, StringRef PipelineText);
|
| 366 |
+
Error parsePassPipeline(LoopPassManager &LPM, StringRef PipelineText);
|
| 367 |
+
/// @}}
|
| 368 |
+
|
| 369 |
+
/// Parse a textual MIR pipeline into the provided \c MachineFunctionPass
|
| 370 |
+
/// manager.
|
| 371 |
+
/// The format of the textual machine pipeline is a comma separated list of
|
| 372 |
+
/// machine pass names:
|
| 373 |
+
///
|
| 374 |
+
/// machine-funciton-pass,machine-module-pass,...
|
| 375 |
+
///
|
| 376 |
+
/// There is no need to specify the pass nesting, and this function
|
| 377 |
+
/// currently cannot handle the pass nesting.
|
| 378 |
+
Error parsePassPipeline(MachineFunctionPassManager &MFPM,
|
| 379 |
+
StringRef PipelineText);
|
| 380 |
+
|
| 381 |
+
/// Parse a textual alias analysis pipeline into the provided AA manager.
|
| 382 |
+
///
|
| 383 |
+
/// The format of the textual AA pipeline is a comma separated list of AA
|
| 384 |
+
/// pass names:
|
| 385 |
+
///
|
| 386 |
+
/// basic-aa,globals-aa,...
|
| 387 |
+
///
|
| 388 |
+
/// The AA manager is set up such that the provided alias analyses are tried
|
| 389 |
+
/// in the order specified. See the \c AAManaager documentation for details
|
| 390 |
+
/// about the logic used. This routine just provides the textual mapping
|
| 391 |
+
/// between AA names and the analyses to register with the manager.
|
| 392 |
+
///
|
| 393 |
+
/// Returns false if the text cannot be parsed cleanly. The specific state of
|
| 394 |
+
/// the \p AA manager is unspecified if such an error is encountered and this
|
| 395 |
+
/// returns false.
|
| 396 |
+
Error parseAAPipeline(AAManager &AA, StringRef PipelineText);
|
| 397 |
+
|
| 398 |
+
/// Parse RegAllocFilterName to get RegAllocFilterFunc.
|
| 399 |
+
std::optional<RegAllocFilterFunc>
|
| 400 |
+
parseRegAllocFilter(StringRef RegAllocFilterName);
|
| 401 |
+
|
| 402 |
+
/// Print pass names.
|
| 403 |
+
void printPassNames(raw_ostream &OS);
|
| 404 |
+
|
| 405 |
+
/// Register a callback for a default optimizer pipeline extension
|
| 406 |
+
/// point
|
| 407 |
+
///
|
| 408 |
+
/// This extension point allows adding passes that perform peephole
|
| 409 |
+
/// optimizations similar to the instruction combiner. These passes will be
|
| 410 |
+
/// inserted after each instance of the instruction combiner pass.
|
| 411 |
+
void registerPeepholeEPCallback(
|
| 412 |
+
const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
|
| 413 |
+
PeepholeEPCallbacks.push_back(C);
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
/// Register a callback for a default optimizer pipeline extension
|
| 417 |
+
/// point
|
| 418 |
+
///
|
| 419 |
+
/// This extension point allows adding late loop canonicalization and
|
| 420 |
+
/// simplification passes. This is the last point in the loop optimization
|
| 421 |
+
/// pipeline before loop deletion. Each pass added
|
| 422 |
+
/// here must be an instance of LoopPass.
|
| 423 |
+
/// This is the place to add passes that can remove loops, such as target-
|
| 424 |
+
/// specific loop idiom recognition.
|
| 425 |
+
void registerLateLoopOptimizationsEPCallback(
|
| 426 |
+
const std::function<void(LoopPassManager &, OptimizationLevel)> &C) {
|
| 427 |
+
LateLoopOptimizationsEPCallbacks.push_back(C);
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
/// Register a callback for a default optimizer pipeline extension
|
| 431 |
+
/// point
|
| 432 |
+
///
|
| 433 |
+
/// This extension point allows adding loop passes to the end of the loop
|
| 434 |
+
/// optimizer.
|
| 435 |
+
void registerLoopOptimizerEndEPCallback(
|
| 436 |
+
const std::function<void(LoopPassManager &, OptimizationLevel)> &C) {
|
| 437 |
+
LoopOptimizerEndEPCallbacks.push_back(C);
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
/// Register a callback for a default optimizer pipeline extension
|
| 441 |
+
/// point
|
| 442 |
+
///
|
| 443 |
+
/// This extension point allows adding optimization passes after most of the
|
| 444 |
+
/// main optimizations, but before the last cleanup-ish optimizations.
|
| 445 |
+
void registerScalarOptimizerLateEPCallback(
|
| 446 |
+
const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
|
| 447 |
+
ScalarOptimizerLateEPCallbacks.push_back(C);
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
/// Register a callback for a default optimizer pipeline extension
|
| 451 |
+
/// point
|
| 452 |
+
///
|
| 453 |
+
/// This extension point allows adding CallGraphSCC passes at the end of the
|
| 454 |
+
/// main CallGraphSCC passes and before any function simplification passes run
|
| 455 |
+
/// by CGPassManager.
|
| 456 |
+
void registerCGSCCOptimizerLateEPCallback(
|
| 457 |
+
const std::function<void(CGSCCPassManager &, OptimizationLevel)> &C) {
|
| 458 |
+
CGSCCOptimizerLateEPCallbacks.push_back(C);
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
/// Register a callback for a default optimizer pipeline extension
|
| 462 |
+
/// point
|
| 463 |
+
///
|
| 464 |
+
/// This extension point allows adding optimization passes before the
|
| 465 |
+
/// vectorizer and other highly target specific optimization passes are
|
| 466 |
+
/// executed.
|
| 467 |
+
void registerVectorizerStartEPCallback(
|
| 468 |
+
const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
|
| 469 |
+
VectorizerStartEPCallbacks.push_back(C);
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
/// Register a callback for a default optimizer pipeline extension
|
| 473 |
+
/// point
|
| 474 |
+
///
|
| 475 |
+
/// This extension point allows adding optimization passes after the
|
| 476 |
+
/// vectorizer and other highly target specific optimization passes are
|
| 477 |
+
/// executed.
|
| 478 |
+
void registerVectorizerEndEPCallback(
|
| 479 |
+
const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
|
| 480 |
+
VectorizerEndEPCallbacks.push_back(C);
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
/// Register a callback for a default optimizer pipeline extension point.
|
| 484 |
+
///
|
| 485 |
+
/// This extension point allows adding optimization once at the start of the
|
| 486 |
+
/// pipeline. This does not apply to 'backend' compiles (LTO and ThinLTO
|
| 487 |
+
/// link-time pipelines).
|
| 488 |
+
void registerPipelineStartEPCallback(
|
| 489 |
+
const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
|
| 490 |
+
PipelineStartEPCallbacks.push_back(C);
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
/// Register a callback for a default optimizer pipeline extension point.
|
| 494 |
+
///
|
| 495 |
+
/// This extension point allows adding optimization right after passes that do
|
| 496 |
+
/// basic simplification of the input IR.
|
| 497 |
+
void registerPipelineEarlySimplificationEPCallback(
|
| 498 |
+
const std::function<void(ModulePassManager &, OptimizationLevel,
|
| 499 |
+
ThinOrFullLTOPhase)> &C) {
|
| 500 |
+
PipelineEarlySimplificationEPCallbacks.push_back(C);
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
/// Register a callback for a default optimizer pipeline extension point
|
| 504 |
+
///
|
| 505 |
+
/// This extension point allows adding optimizations before the function
|
| 506 |
+
/// optimization pipeline.
|
| 507 |
+
void registerOptimizerEarlyEPCallback(
|
| 508 |
+
const std::function<void(ModulePassManager &, OptimizationLevel,
|
| 509 |
+
ThinOrFullLTOPhase Phase)> &C) {
|
| 510 |
+
OptimizerEarlyEPCallbacks.push_back(C);
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
/// Register a callback for a default optimizer pipeline extension point
|
| 514 |
+
///
|
| 515 |
+
/// This extension point allows adding optimizations at the very end of the
|
| 516 |
+
/// function optimization pipeline.
|
| 517 |
+
void registerOptimizerLastEPCallback(
|
| 518 |
+
const std::function<void(ModulePassManager &, OptimizationLevel,
|
| 519 |
+
ThinOrFullLTOPhase)> &C) {
|
| 520 |
+
OptimizerLastEPCallbacks.push_back(C);
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
/// Register a callback for a default optimizer pipeline extension point
|
| 524 |
+
///
|
| 525 |
+
/// This extension point allows adding optimizations at the start of the full
|
| 526 |
+
/// LTO pipeline.
|
| 527 |
+
void registerFullLinkTimeOptimizationEarlyEPCallback(
|
| 528 |
+
const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
|
| 529 |
+
FullLinkTimeOptimizationEarlyEPCallbacks.push_back(C);
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
/// Register a callback for a default optimizer pipeline extension point
|
| 533 |
+
///
|
| 534 |
+
/// This extension point allows adding optimizations at the end of the full
|
| 535 |
+
/// LTO pipeline.
|
| 536 |
+
void registerFullLinkTimeOptimizationLastEPCallback(
|
| 537 |
+
const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
|
| 538 |
+
FullLinkTimeOptimizationLastEPCallbacks.push_back(C);
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
/// Register a callback for parsing an AliasAnalysis Name to populate
|
| 542 |
+
/// the given AAManager \p AA
|
| 543 |
+
void registerParseAACallback(
|
| 544 |
+
const std::function<bool(StringRef Name, AAManager &AA)> &C) {
|
| 545 |
+
AAParsingCallbacks.push_back(C);
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
/// {{@ Register callbacks for analysis registration with this PassBuilder
|
| 549 |
+
/// instance.
|
| 550 |
+
/// Callees register their analyses with the given AnalysisManager objects.
|
| 551 |
+
void registerAnalysisRegistrationCallback(
|
| 552 |
+
const std::function<void(CGSCCAnalysisManager &)> &C) {
|
| 553 |
+
CGSCCAnalysisRegistrationCallbacks.push_back(C);
|
| 554 |
+
}
|
| 555 |
+
void registerAnalysisRegistrationCallback(
|
| 556 |
+
const std::function<void(FunctionAnalysisManager &)> &C) {
|
| 557 |
+
FunctionAnalysisRegistrationCallbacks.push_back(C);
|
| 558 |
+
}
|
| 559 |
+
void registerAnalysisRegistrationCallback(
|
| 560 |
+
const std::function<void(LoopAnalysisManager &)> &C) {
|
| 561 |
+
LoopAnalysisRegistrationCallbacks.push_back(C);
|
| 562 |
+
}
|
| 563 |
+
void registerAnalysisRegistrationCallback(
|
| 564 |
+
const std::function<void(ModuleAnalysisManager &)> &C) {
|
| 565 |
+
ModuleAnalysisRegistrationCallbacks.push_back(C);
|
| 566 |
+
}
|
| 567 |
+
void registerAnalysisRegistrationCallback(
|
| 568 |
+
const std::function<void(MachineFunctionAnalysisManager &)> &C) {
|
| 569 |
+
MachineFunctionAnalysisRegistrationCallbacks.push_back(C);
|
| 570 |
+
}
|
| 571 |
+
/// @}}
|
| 572 |
+
|
| 573 |
+
/// {{@ Register pipeline parsing callbacks with this pass builder instance.
|
| 574 |
+
/// Using these callbacks, callers can parse both a single pass name, as well
|
| 575 |
+
/// as entire sub-pipelines, and populate the PassManager instance
|
| 576 |
+
/// accordingly.
|
| 577 |
+
void registerPipelineParsingCallback(
|
| 578 |
+
const std::function<bool(StringRef Name, CGSCCPassManager &,
|
| 579 |
+
ArrayRef<PipelineElement>)> &C) {
|
| 580 |
+
CGSCCPipelineParsingCallbacks.push_back(C);
|
| 581 |
+
}
|
| 582 |
+
void registerPipelineParsingCallback(
|
| 583 |
+
const std::function<bool(StringRef Name, FunctionPassManager &,
|
| 584 |
+
ArrayRef<PipelineElement>)> &C) {
|
| 585 |
+
FunctionPipelineParsingCallbacks.push_back(C);
|
| 586 |
+
}
|
| 587 |
+
void registerPipelineParsingCallback(
|
| 588 |
+
const std::function<bool(StringRef Name, LoopPassManager &,
|
| 589 |
+
ArrayRef<PipelineElement>)> &C) {
|
| 590 |
+
LoopPipelineParsingCallbacks.push_back(C);
|
| 591 |
+
}
|
| 592 |
+
void registerPipelineParsingCallback(
|
| 593 |
+
const std::function<bool(StringRef Name, ModulePassManager &,
|
| 594 |
+
ArrayRef<PipelineElement>)> &C) {
|
| 595 |
+
ModulePipelineParsingCallbacks.push_back(C);
|
| 596 |
+
}
|
| 597 |
+
void registerPipelineParsingCallback(
|
| 598 |
+
const std::function<bool(StringRef Name, MachineFunctionPassManager &,
|
| 599 |
+
ArrayRef<PipelineElement>)> &C) {
|
| 600 |
+
MachineFunctionPipelineParsingCallbacks.push_back(C);
|
| 601 |
+
}
|
| 602 |
+
/// @}}
|
| 603 |
+
|
| 604 |
+
/// Register callbacks to parse target specific filter field if regalloc pass
|
| 605 |
+
/// needs it. E.g. AMDGPU requires regalloc passes can handle sgpr and vgpr
|
| 606 |
+
/// separately.
|
| 607 |
+
void registerRegClassFilterParsingCallback(
|
| 608 |
+
const std::function<RegAllocFilterFunc(StringRef)> &C) {
|
| 609 |
+
RegClassFilterParsingCallbacks.push_back(C);
|
| 610 |
+
}
|
| 611 |
+
|
| 612 |
+
/// Register a callback for a top-level pipeline entry.
|
| 613 |
+
///
|
| 614 |
+
/// If the PassManager type is not given at the top level of the pipeline
|
| 615 |
+
/// text, this Callback should be used to determine the appropriate stack of
|
| 616 |
+
/// PassManagers and populate the passed ModulePassManager.
|
| 617 |
+
void registerParseTopLevelPipelineCallback(
|
| 618 |
+
const std::function<bool(ModulePassManager &, ArrayRef<PipelineElement>)>
|
| 619 |
+
&C);
|
| 620 |
+
|
| 621 |
+
/// Add PGOInstrumenation passes for O0 only.
|
| 622 |
+
void addPGOInstrPassesForO0(ModulePassManager &MPM, bool RunProfileGen,
|
| 623 |
+
bool IsCS, bool AtomicCounterUpdate,
|
| 624 |
+
std::string ProfileFile,
|
| 625 |
+
std::string ProfileRemappingFile,
|
| 626 |
+
IntrusiveRefCntPtr<vfs::FileSystem> FS);
|
| 627 |
+
|
| 628 |
+
/// Returns PIC. External libraries can use this to register pass
|
| 629 |
+
/// instrumentation callbacks.
|
| 630 |
+
PassInstrumentationCallbacks *getPassInstrumentationCallbacks() const {
|
| 631 |
+
return PIC;
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
// Invoke the callbacks registered for the various extension points.
|
| 635 |
+
// Custom pipelines should use these to invoke the callbacks registered
|
| 636 |
+
// by TargetMachines and other clients.
|
| 637 |
+
void invokePeepholeEPCallbacks(FunctionPassManager &FPM,
|
| 638 |
+
OptimizationLevel Level);
|
| 639 |
+
void invokeLateLoopOptimizationsEPCallbacks(LoopPassManager &LPM,
|
| 640 |
+
OptimizationLevel Level);
|
| 641 |
+
void invokeLoopOptimizerEndEPCallbacks(LoopPassManager &LPM,
|
| 642 |
+
OptimizationLevel Level);
|
| 643 |
+
void invokeScalarOptimizerLateEPCallbacks(FunctionPassManager &FPM,
|
| 644 |
+
OptimizationLevel Level);
|
| 645 |
+
void invokeCGSCCOptimizerLateEPCallbacks(CGSCCPassManager &CGPM,
|
| 646 |
+
OptimizationLevel Level);
|
| 647 |
+
void invokeVectorizerStartEPCallbacks(FunctionPassManager &FPM,
|
| 648 |
+
OptimizationLevel Level);
|
| 649 |
+
void invokeVectorizerEndEPCallbacks(FunctionPassManager &FPM,
|
| 650 |
+
OptimizationLevel Level);
|
| 651 |
+
void invokeOptimizerEarlyEPCallbacks(ModulePassManager &MPM,
|
| 652 |
+
OptimizationLevel Level,
|
| 653 |
+
ThinOrFullLTOPhase Phase);
|
| 654 |
+
void invokeOptimizerLastEPCallbacks(ModulePassManager &MPM,
|
| 655 |
+
OptimizationLevel Level,
|
| 656 |
+
ThinOrFullLTOPhase Phase);
|
| 657 |
+
void invokeFullLinkTimeOptimizationEarlyEPCallbacks(ModulePassManager &MPM,
|
| 658 |
+
OptimizationLevel Level);
|
| 659 |
+
void invokeFullLinkTimeOptimizationLastEPCallbacks(ModulePassManager &MPM,
|
| 660 |
+
OptimizationLevel Level);
|
| 661 |
+
void invokePipelineStartEPCallbacks(ModulePassManager &MPM,
|
| 662 |
+
OptimizationLevel Level);
|
| 663 |
+
void invokePipelineEarlySimplificationEPCallbacks(ModulePassManager &MPM,
|
| 664 |
+
OptimizationLevel Level,
|
| 665 |
+
ThinOrFullLTOPhase Phase);
|
| 666 |
+
|
| 667 |
+
static bool checkParametrizedPassName(StringRef Name, StringRef PassName) {
|
| 668 |
+
if (!Name.consume_front(PassName))
|
| 669 |
+
return false;
|
| 670 |
+
// normal pass name w/o parameters == default parameters
|
| 671 |
+
if (Name.empty())
|
| 672 |
+
return true;
|
| 673 |
+
return Name.starts_with("<") && Name.ends_with(">");
|
| 674 |
+
}
|
| 675 |
+
|
| 676 |
+
/// This performs customized parsing of pass name with parameters.
|
| 677 |
+
///
|
| 678 |
+
/// We do not need parametrization of passes in textual pipeline very often,
|
| 679 |
+
/// yet on a rare occasion ability to specify parameters right there can be
|
| 680 |
+
/// useful.
|
| 681 |
+
///
|
| 682 |
+
/// \p Name - parameterized specification of a pass from a textual pipeline
|
| 683 |
+
/// is a string in a form of :
|
| 684 |
+
/// PassName '<' parameter-list '>'
|
| 685 |
+
///
|
| 686 |
+
/// Parameter list is being parsed by the parser callable argument, \p Parser,
|
| 687 |
+
/// It takes a string-ref of parameters and returns either StringError or a
|
| 688 |
+
/// parameter list in a form of a custom parameters type, all wrapped into
|
| 689 |
+
/// Expected<> template class.
|
| 690 |
+
///
|
| 691 |
+
template <typename ParametersParseCallableT>
|
| 692 |
+
static auto parsePassParameters(ParametersParseCallableT &&Parser,
|
| 693 |
+
StringRef Name, StringRef PassName)
|
| 694 |
+
-> decltype(Parser(StringRef{})) {
|
| 695 |
+
using ParametersT = typename decltype(Parser(StringRef{}))::value_type;
|
| 696 |
+
|
| 697 |
+
StringRef Params = Name;
|
| 698 |
+
if (!Params.consume_front(PassName)) {
|
| 699 |
+
llvm_unreachable(
|
| 700 |
+
"unable to strip pass name from parametrized pass specification");
|
| 701 |
+
}
|
| 702 |
+
if (!Params.empty() &&
|
| 703 |
+
(!Params.consume_front("<") || !Params.consume_back(">"))) {
|
| 704 |
+
llvm_unreachable("invalid format for parametrized pass name");
|
| 705 |
+
}
|
| 706 |
+
|
| 707 |
+
Expected<ParametersT> Result = Parser(Params);
|
| 708 |
+
assert((Result || Result.template errorIsA<StringError>()) &&
|
| 709 |
+
"Pass parameter parser can only return StringErrors.");
|
| 710 |
+
return Result;
|
| 711 |
+
}
|
| 712 |
+
|
| 713 |
+
/// Handle passes only accept one bool-valued parameter.
|
| 714 |
+
///
|
| 715 |
+
/// \return false when Params is empty.
|
| 716 |
+
static Expected<bool> parseSinglePassOption(StringRef Params,
|
| 717 |
+
StringRef OptionName,
|
| 718 |
+
StringRef PassName);
|
| 719 |
+
|
| 720 |
+
private:
|
| 721 |
+
// O1 pass pipeline
|
| 722 |
+
FunctionPassManager
|
| 723 |
+
buildO1FunctionSimplificationPipeline(OptimizationLevel Level,
|
| 724 |
+
ThinOrFullLTOPhase Phase);
|
| 725 |
+
|
| 726 |
+
void addRequiredLTOPreLinkPasses(ModulePassManager &MPM);
|
| 727 |
+
|
| 728 |
+
void addVectorPasses(OptimizationLevel Level, FunctionPassManager &FPM,
|
| 729 |
+
bool IsFullLTO);
|
| 730 |
+
|
| 731 |
+
static std::optional<std::vector<PipelineElement>>
|
| 732 |
+
parsePipelineText(StringRef Text);
|
| 733 |
+
|
| 734 |
+
Error parseModulePass(ModulePassManager &MPM, const PipelineElement &E);
|
| 735 |
+
Error parseCGSCCPass(CGSCCPassManager &CGPM, const PipelineElement &E);
|
| 736 |
+
Error parseFunctionPass(FunctionPassManager &FPM, const PipelineElement &E);
|
| 737 |
+
Error parseLoopPass(LoopPassManager &LPM, const PipelineElement &E);
|
| 738 |
+
Error parseMachinePass(MachineFunctionPassManager &MFPM,
|
| 739 |
+
const PipelineElement &E);
|
| 740 |
+
bool parseAAPassName(AAManager &AA, StringRef Name);
|
| 741 |
+
|
| 742 |
+
Error parseMachinePassPipeline(MachineFunctionPassManager &MFPM,
|
| 743 |
+
ArrayRef<PipelineElement> Pipeline);
|
| 744 |
+
Error parseLoopPassPipeline(LoopPassManager &LPM,
|
| 745 |
+
ArrayRef<PipelineElement> Pipeline);
|
| 746 |
+
Error parseFunctionPassPipeline(FunctionPassManager &FPM,
|
| 747 |
+
ArrayRef<PipelineElement> Pipeline);
|
| 748 |
+
Error parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
|
| 749 |
+
ArrayRef<PipelineElement> Pipeline);
|
| 750 |
+
Error parseModulePassPipeline(ModulePassManager &MPM,
|
| 751 |
+
ArrayRef<PipelineElement> Pipeline);
|
| 752 |
+
|
| 753 |
+
// Adds passes to do pre-inlining and related cleanup passes before
|
| 754 |
+
// profile instrumentation/matching (to enable better context sensitivity),
|
| 755 |
+
// and for memprof to enable better matching with missing debug frames.
|
| 756 |
+
void addPreInlinerPasses(ModulePassManager &MPM, OptimizationLevel Level,
|
| 757 |
+
ThinOrFullLTOPhase LTOPhase);
|
| 758 |
+
|
| 759 |
+
void addPGOInstrPasses(ModulePassManager &MPM, OptimizationLevel Level,
|
| 760 |
+
bool RunProfileGen, bool IsCS,
|
| 761 |
+
bool AtomicCounterUpdate, std::string ProfileFile,
|
| 762 |
+
std::string ProfileRemappingFile,
|
| 763 |
+
IntrusiveRefCntPtr<vfs::FileSystem> FS);
|
| 764 |
+
void addPostPGOLoopRotation(ModulePassManager &MPM, OptimizationLevel Level);
|
| 765 |
+
|
| 766 |
+
// Extension Point callbacks
|
| 767 |
+
SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
|
| 768 |
+
PeepholeEPCallbacks;
|
| 769 |
+
SmallVector<std::function<void(LoopPassManager &, OptimizationLevel)>, 2>
|
| 770 |
+
LateLoopOptimizationsEPCallbacks;
|
| 771 |
+
SmallVector<std::function<void(LoopPassManager &, OptimizationLevel)>, 2>
|
| 772 |
+
LoopOptimizerEndEPCallbacks;
|
| 773 |
+
SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
|
| 774 |
+
ScalarOptimizerLateEPCallbacks;
|
| 775 |
+
SmallVector<std::function<void(CGSCCPassManager &, OptimizationLevel)>, 2>
|
| 776 |
+
CGSCCOptimizerLateEPCallbacks;
|
| 777 |
+
SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
|
| 778 |
+
VectorizerStartEPCallbacks;
|
| 779 |
+
SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
|
| 780 |
+
VectorizerEndEPCallbacks;
|
| 781 |
+
// Module callbacks
|
| 782 |
+
SmallVector<std::function<void(ModulePassManager &, OptimizationLevel,
|
| 783 |
+
ThinOrFullLTOPhase)>,
|
| 784 |
+
2>
|
| 785 |
+
OptimizerEarlyEPCallbacks;
|
| 786 |
+
SmallVector<std::function<void(ModulePassManager &, OptimizationLevel,
|
| 787 |
+
ThinOrFullLTOPhase)>,
|
| 788 |
+
2>
|
| 789 |
+
OptimizerLastEPCallbacks;
|
| 790 |
+
SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
|
| 791 |
+
FullLinkTimeOptimizationEarlyEPCallbacks;
|
| 792 |
+
SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
|
| 793 |
+
FullLinkTimeOptimizationLastEPCallbacks;
|
| 794 |
+
SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
|
| 795 |
+
PipelineStartEPCallbacks;
|
| 796 |
+
SmallVector<std::function<void(ModulePassManager &, OptimizationLevel,
|
| 797 |
+
ThinOrFullLTOPhase)>,
|
| 798 |
+
2>
|
| 799 |
+
PipelineEarlySimplificationEPCallbacks;
|
| 800 |
+
|
| 801 |
+
SmallVector<std::function<void(ModuleAnalysisManager &)>, 2>
|
| 802 |
+
ModuleAnalysisRegistrationCallbacks;
|
| 803 |
+
SmallVector<std::function<bool(StringRef, ModulePassManager &,
|
| 804 |
+
ArrayRef<PipelineElement>)>,
|
| 805 |
+
2>
|
| 806 |
+
ModulePipelineParsingCallbacks;
|
| 807 |
+
SmallVector<
|
| 808 |
+
std::function<bool(ModulePassManager &, ArrayRef<PipelineElement>)>, 2>
|
| 809 |
+
TopLevelPipelineParsingCallbacks;
|
| 810 |
+
// CGSCC callbacks
|
| 811 |
+
SmallVector<std::function<void(CGSCCAnalysisManager &)>, 2>
|
| 812 |
+
CGSCCAnalysisRegistrationCallbacks;
|
| 813 |
+
SmallVector<std::function<bool(StringRef, CGSCCPassManager &,
|
| 814 |
+
ArrayRef<PipelineElement>)>,
|
| 815 |
+
2>
|
| 816 |
+
CGSCCPipelineParsingCallbacks;
|
| 817 |
+
// Function callbacks
|
| 818 |
+
SmallVector<std::function<void(FunctionAnalysisManager &)>, 2>
|
| 819 |
+
FunctionAnalysisRegistrationCallbacks;
|
| 820 |
+
SmallVector<std::function<bool(StringRef, FunctionPassManager &,
|
| 821 |
+
ArrayRef<PipelineElement>)>,
|
| 822 |
+
2>
|
| 823 |
+
FunctionPipelineParsingCallbacks;
|
| 824 |
+
// Loop callbacks
|
| 825 |
+
SmallVector<std::function<void(LoopAnalysisManager &)>, 2>
|
| 826 |
+
LoopAnalysisRegistrationCallbacks;
|
| 827 |
+
SmallVector<std::function<bool(StringRef, LoopPassManager &,
|
| 828 |
+
ArrayRef<PipelineElement>)>,
|
| 829 |
+
2>
|
| 830 |
+
LoopPipelineParsingCallbacks;
|
| 831 |
+
// AA callbacks
|
| 832 |
+
SmallVector<std::function<bool(StringRef Name, AAManager &AA)>, 2>
|
| 833 |
+
AAParsingCallbacks;
|
| 834 |
+
// Machine pass callbackcs
|
| 835 |
+
SmallVector<std::function<void(MachineFunctionAnalysisManager &)>, 2>
|
| 836 |
+
MachineFunctionAnalysisRegistrationCallbacks;
|
| 837 |
+
SmallVector<std::function<bool(StringRef, MachineFunctionPassManager &,
|
| 838 |
+
ArrayRef<PipelineElement>)>,
|
| 839 |
+
2>
|
| 840 |
+
MachineFunctionPipelineParsingCallbacks;
|
| 841 |
+
// Callbacks to parse `filter` parameter in register allocation passes
|
| 842 |
+
SmallVector<std::function<RegAllocFilterFunc(StringRef)>, 2>
|
| 843 |
+
RegClassFilterParsingCallbacks;
|
| 844 |
+
};
|
| 845 |
+
|
| 846 |
+
/// This utility template takes care of adding require<> and invalidate<>
|
| 847 |
+
/// passes for an analysis to a given \c PassManager. It is intended to be used
|
| 848 |
+
/// during parsing of a pass pipeline when parsing a single PipelineName.
|
| 849 |
+
/// When registering a new function analysis FancyAnalysis with the pass
|
| 850 |
+
/// pipeline name "fancy-analysis", a matching ParsePipelineCallback could look
|
| 851 |
+
/// like this:
|
| 852 |
+
///
|
| 853 |
+
/// static bool parseFunctionPipeline(StringRef Name, FunctionPassManager &FPM,
|
| 854 |
+
/// ArrayRef<PipelineElement> P) {
|
| 855 |
+
/// if (parseAnalysisUtilityPasses<FancyAnalysis>("fancy-analysis", Name,
|
| 856 |
+
/// FPM))
|
| 857 |
+
/// return true;
|
| 858 |
+
/// return false;
|
| 859 |
+
/// }
|
| 860 |
+
template <typename AnalysisT, typename IRUnitT, typename AnalysisManagerT,
|
| 861 |
+
typename... ExtraArgTs>
|
| 862 |
+
bool parseAnalysisUtilityPasses(
|
| 863 |
+
StringRef AnalysisName, StringRef PipelineName,
|
| 864 |
+
PassManager<IRUnitT, AnalysisManagerT, ExtraArgTs...> &PM) {
|
| 865 |
+
if (!PipelineName.ends_with(">"))
|
| 866 |
+
return false;
|
| 867 |
+
// See if this is an invalidate<> pass name
|
| 868 |
+
if (PipelineName.starts_with("invalidate<")) {
|
| 869 |
+
PipelineName = PipelineName.substr(11, PipelineName.size() - 12);
|
| 870 |
+
if (PipelineName != AnalysisName)
|
| 871 |
+
return false;
|
| 872 |
+
PM.addPass(InvalidateAnalysisPass<AnalysisT>());
|
| 873 |
+
return true;
|
| 874 |
+
}
|
| 875 |
+
|
| 876 |
+
// See if this is a require<> pass name
|
| 877 |
+
if (PipelineName.starts_with("require<")) {
|
| 878 |
+
PipelineName = PipelineName.substr(8, PipelineName.size() - 9);
|
| 879 |
+
if (PipelineName != AnalysisName)
|
| 880 |
+
return false;
|
| 881 |
+
PM.addPass(RequireAnalysisPass<AnalysisT, IRUnitT, AnalysisManagerT,
|
| 882 |
+
ExtraArgTs...>());
|
| 883 |
+
return true;
|
| 884 |
+
}
|
| 885 |
+
|
| 886 |
+
return false;
|
| 887 |
+
}
|
| 888 |
+
|
| 889 |
+
// These are special since they are only for testing purposes.
|
| 890 |
+
|
| 891 |
+
/// No-op module pass which does nothing.
|
| 892 |
+
struct NoOpModulePass : PassInfoMixin<NoOpModulePass> {
|
| 893 |
+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &) {
|
| 894 |
+
return PreservedAnalyses::all();
|
| 895 |
+
}
|
| 896 |
+
};
|
| 897 |
+
|
| 898 |
+
/// No-op module analysis.
|
| 899 |
+
class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
|
| 900 |
+
friend AnalysisInfoMixin<NoOpModuleAnalysis>;
|
| 901 |
+
static AnalysisKey Key;
|
| 902 |
+
|
| 903 |
+
public:
|
| 904 |
+
struct Result {};
|
| 905 |
+
Result run(Module &, ModuleAnalysisManager &) { return Result(); }
|
| 906 |
+
};
|
| 907 |
+
|
| 908 |
+
/// No-op CGSCC pass which does nothing.
|
| 909 |
+
struct NoOpCGSCCPass : PassInfoMixin<NoOpCGSCCPass> {
|
| 910 |
+
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &,
|
| 911 |
+
LazyCallGraph &, CGSCCUpdateResult &UR) {
|
| 912 |
+
return PreservedAnalyses::all();
|
| 913 |
+
}
|
| 914 |
+
};
|
| 915 |
+
|
| 916 |
+
/// No-op CGSCC analysis.
|
| 917 |
+
class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
|
| 918 |
+
friend AnalysisInfoMixin<NoOpCGSCCAnalysis>;
|
| 919 |
+
static AnalysisKey Key;
|
| 920 |
+
|
| 921 |
+
public:
|
| 922 |
+
struct Result {};
|
| 923 |
+
Result run(LazyCallGraph::SCC &, CGSCCAnalysisManager &, LazyCallGraph &G) {
|
| 924 |
+
return Result();
|
| 925 |
+
}
|
| 926 |
+
};
|
| 927 |
+
|
| 928 |
+
/// No-op function pass which does nothing.
|
| 929 |
+
struct NoOpFunctionPass : PassInfoMixin<NoOpFunctionPass> {
|
| 930 |
+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
|
| 931 |
+
return PreservedAnalyses::all();
|
| 932 |
+
}
|
| 933 |
+
};
|
| 934 |
+
|
| 935 |
+
/// No-op function analysis.
|
| 936 |
+
class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
|
| 937 |
+
friend AnalysisInfoMixin<NoOpFunctionAnalysis>;
|
| 938 |
+
static AnalysisKey Key;
|
| 939 |
+
|
| 940 |
+
public:
|
| 941 |
+
struct Result {};
|
| 942 |
+
Result run(Function &, FunctionAnalysisManager &) { return Result(); }
|
| 943 |
+
};
|
| 944 |
+
|
| 945 |
+
/// No-op loop nest pass which does nothing.
|
| 946 |
+
struct NoOpLoopNestPass : PassInfoMixin<NoOpLoopNestPass> {
|
| 947 |
+
PreservedAnalyses run(LoopNest &L, LoopAnalysisManager &,
|
| 948 |
+
LoopStandardAnalysisResults &, LPMUpdater &) {
|
| 949 |
+
return PreservedAnalyses::all();
|
| 950 |
+
}
|
| 951 |
+
};
|
| 952 |
+
|
| 953 |
+
/// No-op loop pass which does nothing.
|
| 954 |
+
struct NoOpLoopPass : PassInfoMixin<NoOpLoopPass> {
|
| 955 |
+
PreservedAnalyses run(Loop &L, LoopAnalysisManager &,
|
| 956 |
+
LoopStandardAnalysisResults &, LPMUpdater &) {
|
| 957 |
+
return PreservedAnalyses::all();
|
| 958 |
+
}
|
| 959 |
+
};
|
| 960 |
+
|
| 961 |
+
/// No-op machine function pass which does nothing.
|
| 962 |
+
struct NoOpMachineFunctionPass : public PassInfoMixin<NoOpMachineFunctionPass> {
|
| 963 |
+
PreservedAnalyses run(MachineFunction &, MachineFunctionAnalysisManager &) {
|
| 964 |
+
return PreservedAnalyses::all();
|
| 965 |
+
}
|
| 966 |
+
};
|
| 967 |
+
|
| 968 |
+
/// No-op loop analysis.
|
| 969 |
+
class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
|
| 970 |
+
friend AnalysisInfoMixin<NoOpLoopAnalysis>;
|
| 971 |
+
static AnalysisKey Key;
|
| 972 |
+
|
| 973 |
+
public:
|
| 974 |
+
struct Result {};
|
| 975 |
+
Result run(Loop &, LoopAnalysisManager &, LoopStandardAnalysisResults &) {
|
| 976 |
+
return Result();
|
| 977 |
+
}
|
| 978 |
+
};
|
| 979 |
+
|
| 980 |
+
/// Common option used by multiple tools to print pipeline passes
|
| 981 |
+
extern cl::opt<bool> PrintPipelinePasses;
|
| 982 |
+
|
| 983 |
+
}
|
| 984 |
+
|
| 985 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Passes/PassPlugin.h
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- llvm/Passes/PassPlugin.h - Public Plugin API -----------------------===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This defines the public entry point for new-PM pass plugins.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_PASSES_PASSPLUGIN_H
|
| 14 |
+
#define LLVM_PASSES_PASSPLUGIN_H
|
| 15 |
+
|
| 16 |
+
#include "llvm/ADT/StringRef.h"
|
| 17 |
+
#include "llvm/Support/Compiler.h"
|
| 18 |
+
#include "llvm/Support/DynamicLibrary.h"
|
| 19 |
+
#include "llvm/Support/Error.h"
|
| 20 |
+
#include <cstdint>
|
| 21 |
+
#include <string>
|
| 22 |
+
|
| 23 |
+
namespace llvm {
|
| 24 |
+
class PassBuilder;
|
| 25 |
+
|
| 26 |
+
/// \macro LLVM_PLUGIN_API_VERSION
|
| 27 |
+
/// Identifies the API version understood by this plugin.
|
| 28 |
+
///
|
| 29 |
+
/// When a plugin is loaded, the driver will check it's supported plugin version
|
| 30 |
+
/// against that of the plugin. A mismatch is an error. The supported version
|
| 31 |
+
/// will be incremented for ABI-breaking changes to the \c PassPluginLibraryInfo
|
| 32 |
+
/// struct, i.e. when callbacks are added, removed, or reordered.
|
| 33 |
+
#define LLVM_PLUGIN_API_VERSION 1
|
| 34 |
+
|
| 35 |
+
extern "C" {
|
| 36 |
+
/// Information about the plugin required to load its passes
|
| 37 |
+
///
|
| 38 |
+
/// This struct defines the core interface for pass plugins and is supposed to
|
| 39 |
+
/// be filled out by plugin implementors. LLVM-side users of a plugin are
|
| 40 |
+
/// expected to use the \c PassPlugin class below to interface with it.
|
| 41 |
+
struct PassPluginLibraryInfo {
|
| 42 |
+
/// The API version understood by this plugin, usually \c
|
| 43 |
+
/// LLVM_PLUGIN_API_VERSION
|
| 44 |
+
uint32_t APIVersion;
|
| 45 |
+
/// A meaningful name of the plugin.
|
| 46 |
+
const char *PluginName;
|
| 47 |
+
/// The version of the plugin.
|
| 48 |
+
const char *PluginVersion;
|
| 49 |
+
|
| 50 |
+
/// The callback for registering plugin passes with a \c PassBuilder
|
| 51 |
+
/// instance
|
| 52 |
+
void (*RegisterPassBuilderCallbacks)(PassBuilder &);
|
| 53 |
+
};
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/// A loaded pass plugin.
|
| 57 |
+
///
|
| 58 |
+
/// An instance of this class wraps a loaded pass plugin and gives access to
|
| 59 |
+
/// its interface defined by the \c PassPluginLibraryInfo it exposes.
|
| 60 |
+
class PassPlugin {
|
| 61 |
+
public:
|
| 62 |
+
/// Attempts to load a pass plugin from a given file.
|
| 63 |
+
///
|
| 64 |
+
/// \returns Returns an error if either the library cannot be found or loaded,
|
| 65 |
+
/// there is no public entry point, or the plugin implements the wrong API
|
| 66 |
+
/// version.
|
| 67 |
+
static Expected<PassPlugin> Load(const std::string &Filename);
|
| 68 |
+
|
| 69 |
+
/// Get the filename of the loaded plugin.
|
| 70 |
+
StringRef getFilename() const { return Filename; }
|
| 71 |
+
|
| 72 |
+
/// Get the plugin name
|
| 73 |
+
StringRef getPluginName() const { return Info.PluginName; }
|
| 74 |
+
|
| 75 |
+
/// Get the plugin version
|
| 76 |
+
StringRef getPluginVersion() const { return Info.PluginVersion; }
|
| 77 |
+
|
| 78 |
+
/// Get the plugin API version
|
| 79 |
+
uint32_t getAPIVersion() const { return Info.APIVersion; }
|
| 80 |
+
|
| 81 |
+
/// Invoke the PassBuilder callback registration
|
| 82 |
+
void registerPassBuilderCallbacks(PassBuilder &PB) const {
|
| 83 |
+
Info.RegisterPassBuilderCallbacks(PB);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
private:
|
| 87 |
+
PassPlugin(const std::string &Filename, const sys::DynamicLibrary &Library)
|
| 88 |
+
: Filename(Filename), Library(Library), Info() {}
|
| 89 |
+
|
| 90 |
+
std::string Filename;
|
| 91 |
+
sys::DynamicLibrary Library;
|
| 92 |
+
PassPluginLibraryInfo Info;
|
| 93 |
+
};
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/// The public entry point for a pass plugin.
|
| 97 |
+
///
|
| 98 |
+
/// When a plugin is loaded by the driver, it will call this entry point to
|
| 99 |
+
/// obtain information about this plugin and about how to register its passes.
|
| 100 |
+
/// This function needs to be implemented by the plugin, see the example below:
|
| 101 |
+
///
|
| 102 |
+
/// ```
|
| 103 |
+
/// extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
|
| 104 |
+
/// llvmGetPassPluginInfo() {
|
| 105 |
+
/// return {
|
| 106 |
+
/// LLVM_PLUGIN_API_VERSION, "MyPlugin", "v0.1", [](PassBuilder &PB) { ... }
|
| 107 |
+
/// };
|
| 108 |
+
/// }
|
| 109 |
+
/// ```
|
| 110 |
+
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
|
| 111 |
+
llvmGetPassPluginInfo();
|
| 112 |
+
|
| 113 |
+
#endif /* LLVM_PASSES_PASSPLUGIN_H */
|
deps/exla/cache/xla_extension/include/llvm/Passes/StandardInstrumentations.h
ADDED
|
@@ -0,0 +1,641 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- StandardInstrumentations.h ------------------------------*- C++ -*--===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
/// \file
|
| 9 |
+
///
|
| 10 |
+
/// This header defines a class that provides bookkeeping for all standard
|
| 11 |
+
/// (i.e in-tree) pass instrumentations.
|
| 12 |
+
///
|
| 13 |
+
//===----------------------------------------------------------------------===//
|
| 14 |
+
|
| 15 |
+
#ifndef LLVM_PASSES_STANDARDINSTRUMENTATIONS_H
|
| 16 |
+
#define LLVM_PASSES_STANDARDINSTRUMENTATIONS_H
|
| 17 |
+
|
| 18 |
+
#include "llvm/ADT/STLExtras.h"
|
| 19 |
+
#include "llvm/ADT/SmallVector.h"
|
| 20 |
+
#include "llvm/ADT/StringRef.h"
|
| 21 |
+
#include "llvm/ADT/StringSet.h"
|
| 22 |
+
#include "llvm/CodeGen/MachineBasicBlock.h"
|
| 23 |
+
#include "llvm/IR/BasicBlock.h"
|
| 24 |
+
#include "llvm/IR/DebugInfoMetadata.h"
|
| 25 |
+
#include "llvm/IR/DroppedVariableStatsIR.h"
|
| 26 |
+
#include "llvm/IR/OptBisect.h"
|
| 27 |
+
#include "llvm/IR/PassTimingInfo.h"
|
| 28 |
+
#include "llvm/IR/ValueHandle.h"
|
| 29 |
+
#include "llvm/Support/CommandLine.h"
|
| 30 |
+
#include "llvm/Support/TimeProfiler.h"
|
| 31 |
+
#include "llvm/Transforms/IPO/SampleProfileProbe.h"
|
| 32 |
+
|
| 33 |
+
#include <string>
|
| 34 |
+
#include <utility>
|
| 35 |
+
|
| 36 |
+
namespace llvm {
|
| 37 |
+
|
| 38 |
+
class Module;
|
| 39 |
+
class Function;
|
| 40 |
+
class MachineFunction;
|
| 41 |
+
class PassInstrumentationCallbacks;
|
| 42 |
+
|
| 43 |
+
/// Instrumentation to print IR before/after passes.
|
| 44 |
+
///
|
| 45 |
+
/// Needs state to be able to print module after pass that invalidates IR unit
|
| 46 |
+
/// (typically Loop or SCC).
|
| 47 |
+
class PrintIRInstrumentation {
|
| 48 |
+
public:
|
| 49 |
+
~PrintIRInstrumentation();
|
| 50 |
+
|
| 51 |
+
void registerCallbacks(PassInstrumentationCallbacks &PIC);
|
| 52 |
+
|
| 53 |
+
private:
|
| 54 |
+
struct PassRunDescriptor {
|
| 55 |
+
const Module *M;
|
| 56 |
+
const unsigned PassNumber;
|
| 57 |
+
const std::string IRFileDisplayName;
|
| 58 |
+
const std::string IRName;
|
| 59 |
+
const StringRef PassID;
|
| 60 |
+
|
| 61 |
+
PassRunDescriptor(const Module *M, unsigned PassNumber,
|
| 62 |
+
std::string &&IRFileDisplayName, std::string &&IRName,
|
| 63 |
+
const StringRef PassID)
|
| 64 |
+
: M{M}, PassNumber{PassNumber}, IRFileDisplayName(IRFileDisplayName),
|
| 65 |
+
IRName{IRName}, PassID(PassID) {}
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
void printBeforePass(StringRef PassID, Any IR);
|
| 69 |
+
void printAfterPass(StringRef PassID, Any IR);
|
| 70 |
+
void printAfterPassInvalidated(StringRef PassID);
|
| 71 |
+
|
| 72 |
+
bool shouldPrintBeforePass(StringRef PassID);
|
| 73 |
+
bool shouldPrintAfterPass(StringRef PassID);
|
| 74 |
+
bool shouldPrintBeforeCurrentPassNumber();
|
| 75 |
+
bool shouldPrintAfterCurrentPassNumber();
|
| 76 |
+
bool shouldPrintPassNumbers();
|
| 77 |
+
bool shouldPrintBeforeSomePassNumber();
|
| 78 |
+
bool shouldPrintAfterSomePassNumber();
|
| 79 |
+
|
| 80 |
+
void pushPassRunDescriptor(StringRef PassID, Any IR, unsigned PassNumber);
|
| 81 |
+
PassRunDescriptor popPassRunDescriptor(StringRef PassID);
|
| 82 |
+
|
| 83 |
+
enum class IRDumpFileSuffixType {
|
| 84 |
+
Before,
|
| 85 |
+
After,
|
| 86 |
+
Invalidated,
|
| 87 |
+
};
|
| 88 |
+
|
| 89 |
+
static StringRef
|
| 90 |
+
getFileSuffix(PrintIRInstrumentation::IRDumpFileSuffixType Type);
|
| 91 |
+
std::string fetchDumpFilename(StringRef PassId, StringRef IRFileDisplayName,
|
| 92 |
+
unsigned PassNumber,
|
| 93 |
+
IRDumpFileSuffixType SuffixType);
|
| 94 |
+
|
| 95 |
+
PassInstrumentationCallbacks *PIC;
|
| 96 |
+
/// Stack of Pass Run descriptions, enough to print the IR unit after a given
|
| 97 |
+
/// pass.
|
| 98 |
+
SmallVector<PassRunDescriptor, 2> PassRunDescriptorStack;
|
| 99 |
+
|
| 100 |
+
/// Used for print-at-pass-number
|
| 101 |
+
unsigned CurrentPassNumber = 0;
|
| 102 |
+
};
|
| 103 |
+
|
| 104 |
+
class OptNoneInstrumentation {
|
| 105 |
+
public:
|
| 106 |
+
OptNoneInstrumentation(bool DebugLogging) : DebugLogging(DebugLogging) {}
|
| 107 |
+
void registerCallbacks(PassInstrumentationCallbacks &PIC);
|
| 108 |
+
|
| 109 |
+
private:
|
| 110 |
+
bool DebugLogging;
|
| 111 |
+
bool shouldRun(StringRef PassID, Any IR);
|
| 112 |
+
};
|
| 113 |
+
|
| 114 |
+
class OptPassGateInstrumentation {
|
| 115 |
+
LLVMContext &Context;
|
| 116 |
+
bool HasWrittenIR = false;
|
| 117 |
+
public:
|
| 118 |
+
OptPassGateInstrumentation(LLVMContext &Context) : Context(Context) {}
|
| 119 |
+
bool shouldRun(StringRef PassName, Any IR);
|
| 120 |
+
void registerCallbacks(PassInstrumentationCallbacks &PIC);
|
| 121 |
+
};
|
| 122 |
+
|
| 123 |
+
struct PrintPassOptions {
|
| 124 |
+
/// Print adaptors and pass managers.
|
| 125 |
+
bool Verbose = false;
|
| 126 |
+
/// Don't print information for analyses.
|
| 127 |
+
bool SkipAnalyses = false;
|
| 128 |
+
/// Indent based on hierarchy.
|
| 129 |
+
bool Indent = false;
|
| 130 |
+
};
|
| 131 |
+
|
| 132 |
+
// Debug logging for transformation and analysis passes.
|
| 133 |
+
class PrintPassInstrumentation {
|
| 134 |
+
raw_ostream &print();
|
| 135 |
+
|
| 136 |
+
public:
|
| 137 |
+
PrintPassInstrumentation(bool Enabled, PrintPassOptions Opts)
|
| 138 |
+
: Enabled(Enabled), Opts(Opts) {}
|
| 139 |
+
void registerCallbacks(PassInstrumentationCallbacks &PIC);
|
| 140 |
+
|
| 141 |
+
private:
|
| 142 |
+
bool Enabled;
|
| 143 |
+
PrintPassOptions Opts;
|
| 144 |
+
int Indent = 0;
|
| 145 |
+
};
|
| 146 |
+
|
| 147 |
+
class PreservedCFGCheckerInstrumentation {
|
| 148 |
+
public:
|
| 149 |
+
// Keeps sticky poisoned flag for the given basic block once it has been
|
| 150 |
+
// deleted or RAUWed.
|
| 151 |
+
struct BBGuard final : public CallbackVH {
|
| 152 |
+
BBGuard(const BasicBlock *BB) : CallbackVH(BB) {}
|
| 153 |
+
void deleted() override { CallbackVH::deleted(); }
|
| 154 |
+
void allUsesReplacedWith(Value *) override { CallbackVH::deleted(); }
|
| 155 |
+
bool isPoisoned() const { return !getValPtr(); }
|
| 156 |
+
};
|
| 157 |
+
|
| 158 |
+
// CFG is a map BB -> {(Succ, Multiplicity)}, where BB is a non-leaf basic
|
| 159 |
+
// block, {(Succ, Multiplicity)} set of all pairs of the block's successors
|
| 160 |
+
// and the multiplicity of the edge (BB->Succ). As the mapped sets are
|
| 161 |
+
// unordered the order of successors is not tracked by the CFG. In other words
|
| 162 |
+
// this allows basic block successors to be swapped by a pass without
|
| 163 |
+
// reporting a CFG change. CFG can be guarded by basic block tracking pointers
|
| 164 |
+
// in the Graph (BBGuard). That is if any of the block is deleted or RAUWed
|
| 165 |
+
// then the CFG is treated poisoned and no block pointer of the Graph is used.
|
| 166 |
+
struct CFG {
|
| 167 |
+
std::optional<DenseMap<intptr_t, BBGuard>> BBGuards;
|
| 168 |
+
DenseMap<const BasicBlock *, DenseMap<const BasicBlock *, unsigned>> Graph;
|
| 169 |
+
|
| 170 |
+
CFG(const Function *F, bool TrackBBLifetime);
|
| 171 |
+
|
| 172 |
+
bool operator==(const CFG &G) const {
|
| 173 |
+
return !isPoisoned() && !G.isPoisoned() && Graph == G.Graph;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
bool isPoisoned() const {
|
| 177 |
+
return BBGuards && llvm::any_of(*BBGuards, [](const auto &BB) {
|
| 178 |
+
return BB.second.isPoisoned();
|
| 179 |
+
});
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
static void printDiff(raw_ostream &out, const CFG &Before,
|
| 183 |
+
const CFG &After);
|
| 184 |
+
bool invalidate(Function &F, const PreservedAnalyses &PA,
|
| 185 |
+
FunctionAnalysisManager::Invalidator &);
|
| 186 |
+
};
|
| 187 |
+
|
| 188 |
+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
|
| 189 |
+
SmallVector<StringRef, 8> PassStack;
|
| 190 |
+
#endif
|
| 191 |
+
|
| 192 |
+
void registerCallbacks(PassInstrumentationCallbacks &PIC,
|
| 193 |
+
ModuleAnalysisManager &MAM);
|
| 194 |
+
};
|
| 195 |
+
|
| 196 |
+
// Base class for classes that report changes to the IR.
|
| 197 |
+
// It presents an interface for such classes and provides calls
|
| 198 |
+
// on various events as the new pass manager transforms the IR.
|
| 199 |
+
// It also provides filtering of information based on hidden options
|
| 200 |
+
// specifying which functions are interesting.
|
| 201 |
+
// Calls are made for the following events/queries:
|
| 202 |
+
// 1. The initial IR processed.
|
| 203 |
+
// 2. To get the representation of the IR (of type \p T).
|
| 204 |
+
// 3. When a pass does not change the IR.
|
| 205 |
+
// 4. When a pass changes the IR (given both before and after representations
|
| 206 |
+
// of type \p T).
|
| 207 |
+
// 5. When an IR is invalidated.
|
| 208 |
+
// 6. When a pass is run on an IR that is not interesting (based on options).
|
| 209 |
+
// 7. When a pass is ignored (pass manager or adapter pass).
|
| 210 |
+
// 8. To compare two IR representations (of type \p T).
|
| 211 |
+
template <typename IRUnitT> class ChangeReporter {
|
| 212 |
+
protected:
|
| 213 |
+
ChangeReporter(bool RunInVerboseMode) : VerboseMode(RunInVerboseMode) {}
|
| 214 |
+
|
| 215 |
+
public:
|
| 216 |
+
virtual ~ChangeReporter();
|
| 217 |
+
|
| 218 |
+
// Determine if this pass/IR is interesting and if so, save the IR
|
| 219 |
+
// otherwise it is left on the stack without data.
|
| 220 |
+
void saveIRBeforePass(Any IR, StringRef PassID, StringRef PassName);
|
| 221 |
+
// Compare the IR from before the pass after the pass.
|
| 222 |
+
void handleIRAfterPass(Any IR, StringRef PassID, StringRef PassName);
|
| 223 |
+
// Handle the situation where a pass is invalidated.
|
| 224 |
+
void handleInvalidatedPass(StringRef PassID);
|
| 225 |
+
|
| 226 |
+
protected:
|
| 227 |
+
// Register required callbacks.
|
| 228 |
+
void registerRequiredCallbacks(PassInstrumentationCallbacks &PIC);
|
| 229 |
+
|
| 230 |
+
// Called on the first IR processed.
|
| 231 |
+
virtual void handleInitialIR(Any IR) = 0;
|
| 232 |
+
// Called before and after a pass to get the representation of the IR.
|
| 233 |
+
virtual void generateIRRepresentation(Any IR, StringRef PassID,
|
| 234 |
+
IRUnitT &Output) = 0;
|
| 235 |
+
// Called when the pass is not iteresting.
|
| 236 |
+
virtual void omitAfter(StringRef PassID, std::string &Name) = 0;
|
| 237 |
+
// Called when an interesting IR has changed.
|
| 238 |
+
virtual void handleAfter(StringRef PassID, std::string &Name,
|
| 239 |
+
const IRUnitT &Before, const IRUnitT &After,
|
| 240 |
+
Any) = 0;
|
| 241 |
+
// Called when an interesting pass is invalidated.
|
| 242 |
+
virtual void handleInvalidated(StringRef PassID) = 0;
|
| 243 |
+
// Called when the IR or pass is not interesting.
|
| 244 |
+
virtual void handleFiltered(StringRef PassID, std::string &Name) = 0;
|
| 245 |
+
// Called when an ignored pass is encountered.
|
| 246 |
+
virtual void handleIgnored(StringRef PassID, std::string &Name) = 0;
|
| 247 |
+
|
| 248 |
+
// Stack of IRs before passes.
|
| 249 |
+
std::vector<IRUnitT> BeforeStack;
|
| 250 |
+
// Is this the first IR seen?
|
| 251 |
+
bool InitialIR = true;
|
| 252 |
+
|
| 253 |
+
// Run in verbose mode, printing everything?
|
| 254 |
+
const bool VerboseMode;
|
| 255 |
+
};
|
| 256 |
+
|
| 257 |
+
// An abstract template base class that handles printing banners and
|
| 258 |
+
// reporting when things have not changed or are filtered out.
|
| 259 |
+
template <typename IRUnitT>
|
| 260 |
+
class TextChangeReporter : public ChangeReporter<IRUnitT> {
|
| 261 |
+
protected:
|
| 262 |
+
TextChangeReporter(bool Verbose);
|
| 263 |
+
|
| 264 |
+
// Print a module dump of the first IR that is changed.
|
| 265 |
+
void handleInitialIR(Any IR) override;
|
| 266 |
+
// Report that the IR was omitted because it did not change.
|
| 267 |
+
void omitAfter(StringRef PassID, std::string &Name) override;
|
| 268 |
+
// Report that the pass was invalidated.
|
| 269 |
+
void handleInvalidated(StringRef PassID) override;
|
| 270 |
+
// Report that the IR was filtered out.
|
| 271 |
+
void handleFiltered(StringRef PassID, std::string &Name) override;
|
| 272 |
+
// Report that the pass was ignored.
|
| 273 |
+
void handleIgnored(StringRef PassID, std::string &Name) override;
|
| 274 |
+
// Make substitutions in \p S suitable for reporting changes
|
| 275 |
+
// after the pass and then print it.
|
| 276 |
+
|
| 277 |
+
raw_ostream &Out;
|
| 278 |
+
};
|
| 279 |
+
|
| 280 |
+
// A change printer based on the string representation of the IR as created
|
| 281 |
+
// by unwrapAndPrint. The string representation is stored in a std::string
|
| 282 |
+
// to preserve it as the IR changes in each pass. Note that the banner is
|
| 283 |
+
// included in this representation but it is massaged before reporting.
|
| 284 |
+
class IRChangedPrinter : public TextChangeReporter<std::string> {
|
| 285 |
+
public:
|
| 286 |
+
IRChangedPrinter(bool VerboseMode)
|
| 287 |
+
: TextChangeReporter<std::string>(VerboseMode) {}
|
| 288 |
+
~IRChangedPrinter() override;
|
| 289 |
+
void registerCallbacks(PassInstrumentationCallbacks &PIC);
|
| 290 |
+
|
| 291 |
+
protected:
|
| 292 |
+
// Called before and after a pass to get the representation of the IR.
|
| 293 |
+
void generateIRRepresentation(Any IR, StringRef PassID,
|
| 294 |
+
std::string &Output) override;
|
| 295 |
+
// Called when an interesting IR has changed.
|
| 296 |
+
void handleAfter(StringRef PassID, std::string &Name,
|
| 297 |
+
const std::string &Before, const std::string &After,
|
| 298 |
+
Any) override;
|
| 299 |
+
};
|
| 300 |
+
|
| 301 |
+
class IRChangedTester : public IRChangedPrinter {
|
| 302 |
+
public:
|
| 303 |
+
IRChangedTester() : IRChangedPrinter(true) {}
|
| 304 |
+
~IRChangedTester() override;
|
| 305 |
+
void registerCallbacks(PassInstrumentationCallbacks &PIC);
|
| 306 |
+
|
| 307 |
+
protected:
|
| 308 |
+
void handleIR(const std::string &IR, StringRef PassID);
|
| 309 |
+
|
| 310 |
+
// Check initial IR
|
| 311 |
+
void handleInitialIR(Any IR) override;
|
| 312 |
+
// Do nothing.
|
| 313 |
+
void omitAfter(StringRef PassID, std::string &Name) override;
|
| 314 |
+
// Do nothing.
|
| 315 |
+
void handleInvalidated(StringRef PassID) override;
|
| 316 |
+
// Do nothing.
|
| 317 |
+
void handleFiltered(StringRef PassID, std::string &Name) override;
|
| 318 |
+
// Do nothing.
|
| 319 |
+
void handleIgnored(StringRef PassID, std::string &Name) override;
|
| 320 |
+
|
| 321 |
+
// Call test as interesting IR has changed.
|
| 322 |
+
void handleAfter(StringRef PassID, std::string &Name,
|
| 323 |
+
const std::string &Before, const std::string &After,
|
| 324 |
+
Any) override;
|
| 325 |
+
};
|
| 326 |
+
|
| 327 |
+
// Information that needs to be saved for a basic block in order to compare
|
| 328 |
+
// before and after the pass to determine if it was changed by a pass.
|
| 329 |
+
template <typename T> class BlockDataT {
|
| 330 |
+
public:
|
| 331 |
+
BlockDataT(const BasicBlock &B) : Label(B.getName().str()), Data(B) {
|
| 332 |
+
raw_string_ostream SS(Body);
|
| 333 |
+
B.print(SS, nullptr, true, true);
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
BlockDataT(const MachineBasicBlock &B) : Label(B.getName().str()), Data(B) {
|
| 337 |
+
raw_string_ostream SS(Body);
|
| 338 |
+
B.print(SS);
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
bool operator==(const BlockDataT &That) const { return Body == That.Body; }
|
| 342 |
+
bool operator!=(const BlockDataT &That) const { return Body != That.Body; }
|
| 343 |
+
|
| 344 |
+
// Return the label of the represented basic block.
|
| 345 |
+
StringRef getLabel() const { return Label; }
|
| 346 |
+
// Return the string representation of the basic block.
|
| 347 |
+
StringRef getBody() const { return Body; }
|
| 348 |
+
|
| 349 |
+
// Return the associated data
|
| 350 |
+
const T &getData() const { return Data; }
|
| 351 |
+
|
| 352 |
+
protected:
|
| 353 |
+
std::string Label;
|
| 354 |
+
std::string Body;
|
| 355 |
+
|
| 356 |
+
// Extra data associated with a basic block
|
| 357 |
+
T Data;
|
| 358 |
+
};
|
| 359 |
+
|
| 360 |
+
template <typename T> class OrderedChangedData {
|
| 361 |
+
public:
|
| 362 |
+
// Return the names in the order they were saved
|
| 363 |
+
std::vector<std::string> &getOrder() { return Order; }
|
| 364 |
+
const std::vector<std::string> &getOrder() const { return Order; }
|
| 365 |
+
|
| 366 |
+
// Return a map of names to saved representations
|
| 367 |
+
StringMap<T> &getData() { return Data; }
|
| 368 |
+
const StringMap<T> &getData() const { return Data; }
|
| 369 |
+
|
| 370 |
+
bool operator==(const OrderedChangedData<T> &That) const {
|
| 371 |
+
return Data == That.getData();
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
// Call the lambda \p HandlePair on each corresponding pair of data from
|
| 375 |
+
// \p Before and \p After. The order is based on the order in \p After
|
| 376 |
+
// with ones that are only in \p Before interspersed based on where they
|
| 377 |
+
// occur in \p Before. This is used to present the output in an order
|
| 378 |
+
// based on how the data is ordered in LLVM.
|
| 379 |
+
static void report(const OrderedChangedData &Before,
|
| 380 |
+
const OrderedChangedData &After,
|
| 381 |
+
function_ref<void(const T *, const T *)> HandlePair);
|
| 382 |
+
|
| 383 |
+
protected:
|
| 384 |
+
std::vector<std::string> Order;
|
| 385 |
+
StringMap<T> Data;
|
| 386 |
+
};
|
| 387 |
+
|
| 388 |
+
// Do not need extra information for patch-style change reporter.
|
| 389 |
+
class EmptyData {
|
| 390 |
+
public:
|
| 391 |
+
EmptyData(const BasicBlock &) {}
|
| 392 |
+
EmptyData(const MachineBasicBlock &) {}
|
| 393 |
+
};
|
| 394 |
+
|
| 395 |
+
// The data saved for comparing functions.
|
| 396 |
+
template <typename T>
|
| 397 |
+
class FuncDataT : public OrderedChangedData<BlockDataT<T>> {
|
| 398 |
+
public:
|
| 399 |
+
FuncDataT(std::string S) : EntryBlockName(S) {}
|
| 400 |
+
|
| 401 |
+
// Return the name of the entry block
|
| 402 |
+
std::string getEntryBlockName() const { return EntryBlockName; }
|
| 403 |
+
|
| 404 |
+
protected:
|
| 405 |
+
std::string EntryBlockName;
|
| 406 |
+
};
|
| 407 |
+
|
| 408 |
+
// The data saved for comparing IRs.
|
| 409 |
+
template <typename T>
|
| 410 |
+
class IRDataT : public OrderedChangedData<FuncDataT<T>> {};
|
| 411 |
+
|
| 412 |
+
// Abstract template base class for a class that compares two IRs. The
|
| 413 |
+
// class is created with the 2 IRs to compare and then compare is called.
|
| 414 |
+
// The static function analyzeIR is used to build up the IR representation.
|
| 415 |
+
template <typename T> class IRComparer {
|
| 416 |
+
public:
|
| 417 |
+
IRComparer(const IRDataT<T> &Before, const IRDataT<T> &After)
|
| 418 |
+
: Before(Before), After(After) {}
|
| 419 |
+
|
| 420 |
+
// Compare the 2 IRs. \p handleFunctionCompare is called to handle the
|
| 421 |
+
// compare of a function. When \p InModule is set,
|
| 422 |
+
// this function is being handled as part of comparing a module.
|
| 423 |
+
void compare(
|
| 424 |
+
bool CompareModule,
|
| 425 |
+
std::function<void(bool InModule, unsigned Minor,
|
| 426 |
+
const FuncDataT<T> &Before, const FuncDataT<T> &After)>
|
| 427 |
+
CompareFunc);
|
| 428 |
+
|
| 429 |
+
// Analyze \p IR and build the IR representation in \p Data.
|
| 430 |
+
static void analyzeIR(Any IR, IRDataT<T> &Data);
|
| 431 |
+
|
| 432 |
+
protected:
|
| 433 |
+
// Generate the data for \p F into \p Data.
|
| 434 |
+
template <typename FunctionT>
|
| 435 |
+
static bool generateFunctionData(IRDataT<T> &Data, const FunctionT &F);
|
| 436 |
+
|
| 437 |
+
const IRDataT<T> &Before;
|
| 438 |
+
const IRDataT<T> &After;
|
| 439 |
+
};
|
| 440 |
+
|
| 441 |
+
// A change printer that prints out in-line differences in the basic
|
| 442 |
+
// blocks. It uses an InlineComparer to do the comparison so it shows
|
| 443 |
+
// the differences prefixed with '-' and '+' for code that is removed
|
| 444 |
+
// and added, respectively. Changes to the IR that do not affect basic
|
| 445 |
+
// blocks are not reported as having changed the IR. The option
|
| 446 |
+
// -print-module-scope does not affect this change reporter.
|
| 447 |
+
class InLineChangePrinter : public TextChangeReporter<IRDataT<EmptyData>> {
|
| 448 |
+
public:
|
| 449 |
+
InLineChangePrinter(bool VerboseMode, bool ColourMode)
|
| 450 |
+
: TextChangeReporter<IRDataT<EmptyData>>(VerboseMode),
|
| 451 |
+
UseColour(ColourMode) {}
|
| 452 |
+
~InLineChangePrinter() override;
|
| 453 |
+
void registerCallbacks(PassInstrumentationCallbacks &PIC);
|
| 454 |
+
|
| 455 |
+
protected:
|
| 456 |
+
// Create a representation of the IR.
|
| 457 |
+
void generateIRRepresentation(Any IR, StringRef PassID,
|
| 458 |
+
IRDataT<EmptyData> &Output) override;
|
| 459 |
+
|
| 460 |
+
// Called when an interesting IR has changed.
|
| 461 |
+
void handleAfter(StringRef PassID, std::string &Name,
|
| 462 |
+
const IRDataT<EmptyData> &Before,
|
| 463 |
+
const IRDataT<EmptyData> &After, Any) override;
|
| 464 |
+
|
| 465 |
+
void handleFunctionCompare(StringRef Name, StringRef Prefix, StringRef PassID,
|
| 466 |
+
StringRef Divider, bool InModule, unsigned Minor,
|
| 467 |
+
const FuncDataT<EmptyData> &Before,
|
| 468 |
+
const FuncDataT<EmptyData> &After);
|
| 469 |
+
|
| 470 |
+
bool UseColour;
|
| 471 |
+
};
|
| 472 |
+
|
| 473 |
+
class VerifyInstrumentation {
|
| 474 |
+
bool DebugLogging;
|
| 475 |
+
|
| 476 |
+
public:
|
| 477 |
+
VerifyInstrumentation(bool DebugLogging) : DebugLogging(DebugLogging) {}
|
| 478 |
+
void registerCallbacks(PassInstrumentationCallbacks &PIC,
|
| 479 |
+
ModuleAnalysisManager *MAM);
|
| 480 |
+
};
|
| 481 |
+
|
| 482 |
+
/// This class implements --time-trace functionality for new pass manager.
|
| 483 |
+
/// It provides the pass-instrumentation callbacks that measure the pass
|
| 484 |
+
/// execution time. They collect time tracing info by TimeProfiler.
|
| 485 |
+
class TimeProfilingPassesHandler {
|
| 486 |
+
public:
|
| 487 |
+
TimeProfilingPassesHandler();
|
| 488 |
+
// We intend this to be unique per-compilation, thus no copies.
|
| 489 |
+
TimeProfilingPassesHandler(const TimeProfilingPassesHandler &) = delete;
|
| 490 |
+
void operator=(const TimeProfilingPassesHandler &) = delete;
|
| 491 |
+
|
| 492 |
+
void registerCallbacks(PassInstrumentationCallbacks &PIC);
|
| 493 |
+
|
| 494 |
+
private:
|
| 495 |
+
// Implementation of pass instrumentation callbacks.
|
| 496 |
+
void runBeforePass(StringRef PassID, Any IR);
|
| 497 |
+
void runAfterPass();
|
| 498 |
+
};
|
| 499 |
+
|
| 500 |
+
// Class that holds transitions between basic blocks. The transitions
|
| 501 |
+
// are contained in a map of values to names of basic blocks.
|
| 502 |
+
class DCData {
|
| 503 |
+
public:
|
| 504 |
+
// Fill the map with the transitions from basic block \p B.
|
| 505 |
+
DCData(const BasicBlock &B);
|
| 506 |
+
DCData(const MachineBasicBlock &B);
|
| 507 |
+
|
| 508 |
+
// Return an iterator to the names of the successor blocks.
|
| 509 |
+
StringMap<std::string>::const_iterator begin() const {
|
| 510 |
+
return Successors.begin();
|
| 511 |
+
}
|
| 512 |
+
StringMap<std::string>::const_iterator end() const {
|
| 513 |
+
return Successors.end();
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
// Return the label of the basic block reached on a transition on \p S.
|
| 517 |
+
StringRef getSuccessorLabel(StringRef S) const {
|
| 518 |
+
assert(Successors.count(S) == 1 && "Expected to find successor.");
|
| 519 |
+
return Successors.find(S)->getValue();
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
protected:
|
| 523 |
+
// Add a transition to \p Succ on \p Label
|
| 524 |
+
void addSuccessorLabel(StringRef Succ, StringRef Label) {
|
| 525 |
+
std::pair<std::string, std::string> SS{Succ.str(), Label.str()};
|
| 526 |
+
Successors.insert(SS);
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
StringMap<std::string> Successors;
|
| 530 |
+
};
|
| 531 |
+
|
| 532 |
+
// A change reporter that builds a website with links to pdf files showing
|
| 533 |
+
// dot control flow graphs with changed instructions shown in colour.
|
| 534 |
+
class DotCfgChangeReporter : public ChangeReporter<IRDataT<DCData>> {
|
| 535 |
+
public:
|
| 536 |
+
DotCfgChangeReporter(bool Verbose);
|
| 537 |
+
~DotCfgChangeReporter() override;
|
| 538 |
+
void registerCallbacks(PassInstrumentationCallbacks &PIC);
|
| 539 |
+
|
| 540 |
+
protected:
|
| 541 |
+
// Initialize the HTML file and output the header.
|
| 542 |
+
bool initializeHTML();
|
| 543 |
+
|
| 544 |
+
// Called on the first IR processed.
|
| 545 |
+
void handleInitialIR(Any IR) override;
|
| 546 |
+
// Called before and after a pass to get the representation of the IR.
|
| 547 |
+
void generateIRRepresentation(Any IR, StringRef PassID,
|
| 548 |
+
IRDataT<DCData> &Output) override;
|
| 549 |
+
// Called when the pass is not iteresting.
|
| 550 |
+
void omitAfter(StringRef PassID, std::string &Name) override;
|
| 551 |
+
// Called when an interesting IR has changed.
|
| 552 |
+
void handleAfter(StringRef PassID, std::string &Name,
|
| 553 |
+
const IRDataT<DCData> &Before, const IRDataT<DCData> &After,
|
| 554 |
+
Any) override;
|
| 555 |
+
// Called when an interesting pass is invalidated.
|
| 556 |
+
void handleInvalidated(StringRef PassID) override;
|
| 557 |
+
// Called when the IR or pass is not interesting.
|
| 558 |
+
void handleFiltered(StringRef PassID, std::string &Name) override;
|
| 559 |
+
// Called when an ignored pass is encountered.
|
| 560 |
+
void handleIgnored(StringRef PassID, std::string &Name) override;
|
| 561 |
+
|
| 562 |
+
// Generate the pdf file into \p Dir / \p PDFFileName using \p DotFile as
|
| 563 |
+
// input and return the html <a> tag with \Text as the content.
|
| 564 |
+
static std::string genHTML(StringRef Text, StringRef DotFile,
|
| 565 |
+
StringRef PDFFileName);
|
| 566 |
+
|
| 567 |
+
void handleFunctionCompare(StringRef Name, StringRef Prefix, StringRef PassID,
|
| 568 |
+
StringRef Divider, bool InModule, unsigned Minor,
|
| 569 |
+
const FuncDataT<DCData> &Before,
|
| 570 |
+
const FuncDataT<DCData> &After);
|
| 571 |
+
|
| 572 |
+
unsigned N = 0;
|
| 573 |
+
std::unique_ptr<raw_fd_ostream> HTML;
|
| 574 |
+
};
|
| 575 |
+
|
| 576 |
+
// Print IR on crash.
|
| 577 |
+
class PrintCrashIRInstrumentation {
|
| 578 |
+
public:
|
| 579 |
+
PrintCrashIRInstrumentation()
|
| 580 |
+
: SavedIR("*** Dump of IR Before Last Pass Unknown ***") {}
|
| 581 |
+
~PrintCrashIRInstrumentation();
|
| 582 |
+
void registerCallbacks(PassInstrumentationCallbacks &PIC);
|
| 583 |
+
void reportCrashIR();
|
| 584 |
+
|
| 585 |
+
protected:
|
| 586 |
+
std::string SavedIR;
|
| 587 |
+
|
| 588 |
+
private:
|
| 589 |
+
// The crash reporter that will report on a crash.
|
| 590 |
+
static PrintCrashIRInstrumentation *CrashReporter;
|
| 591 |
+
// Crash handler registered when print-on-crash is specified.
|
| 592 |
+
static void SignalHandler(void *);
|
| 593 |
+
};
|
| 594 |
+
|
| 595 |
+
/// This class provides an interface to register all the standard pass
|
| 596 |
+
/// instrumentations and manages their state (if any).
|
| 597 |
+
class StandardInstrumentations {
|
| 598 |
+
PrintIRInstrumentation PrintIR;
|
| 599 |
+
PrintPassInstrumentation PrintPass;
|
| 600 |
+
TimePassesHandler TimePasses;
|
| 601 |
+
TimeProfilingPassesHandler TimeProfilingPasses;
|
| 602 |
+
OptNoneInstrumentation OptNone;
|
| 603 |
+
OptPassGateInstrumentation OptPassGate;
|
| 604 |
+
PreservedCFGCheckerInstrumentation PreservedCFGChecker;
|
| 605 |
+
IRChangedPrinter PrintChangedIR;
|
| 606 |
+
PseudoProbeVerifier PseudoProbeVerification;
|
| 607 |
+
InLineChangePrinter PrintChangedDiff;
|
| 608 |
+
DotCfgChangeReporter WebsiteChangeReporter;
|
| 609 |
+
PrintCrashIRInstrumentation PrintCrashIR;
|
| 610 |
+
IRChangedTester ChangeTester;
|
| 611 |
+
VerifyInstrumentation Verify;
|
| 612 |
+
DroppedVariableStatsIR DroppedStatsIR;
|
| 613 |
+
|
| 614 |
+
bool VerifyEach;
|
| 615 |
+
|
| 616 |
+
public:
|
| 617 |
+
StandardInstrumentations(LLVMContext &Context, bool DebugLogging,
|
| 618 |
+
bool VerifyEach = false,
|
| 619 |
+
PrintPassOptions PrintPassOpts = PrintPassOptions());
|
| 620 |
+
|
| 621 |
+
// Register all the standard instrumentation callbacks. If \p FAM is nullptr
|
| 622 |
+
// then PreservedCFGChecker is not enabled.
|
| 623 |
+
void registerCallbacks(PassInstrumentationCallbacks &PIC,
|
| 624 |
+
ModuleAnalysisManager *MAM = nullptr);
|
| 625 |
+
|
| 626 |
+
TimePassesHandler &getTimePasses() { return TimePasses; }
|
| 627 |
+
};
|
| 628 |
+
|
| 629 |
+
extern template class ChangeReporter<std::string>;
|
| 630 |
+
extern template class TextChangeReporter<std::string>;
|
| 631 |
+
|
| 632 |
+
extern template class BlockDataT<EmptyData>;
|
| 633 |
+
extern template class FuncDataT<EmptyData>;
|
| 634 |
+
extern template class IRDataT<EmptyData>;
|
| 635 |
+
extern template class ChangeReporter<IRDataT<EmptyData>>;
|
| 636 |
+
extern template class TextChangeReporter<IRDataT<EmptyData>>;
|
| 637 |
+
extern template class IRComparer<EmptyData>;
|
| 638 |
+
|
| 639 |
+
} // namespace llvm
|
| 640 |
+
|
| 641 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/Passes/TargetPassRegistry.inc
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- TargetPassRegistry.inc - Registry of passes --------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file is used as the registry of passes in registerPassBuilderCallbacks
|
| 10 |
+
// Just put the following lines in the body of registerPassBuilderCallbacks:
|
| 11 |
+
// #define GET_PASS_REGISTRY "<Target>PassRegistry.def"
|
| 12 |
+
// #include "llvm/Passes/TargetPassRegistry.inc"
|
| 13 |
+
//
|
| 14 |
+
//===----------------------------------------------------------------------===//
|
| 15 |
+
|
| 16 |
+
// NOTE: NO INCLUDE GUARD DESIRED!
|
| 17 |
+
|
| 18 |
+
#ifdef GET_PASS_REGISTRY
|
| 19 |
+
|
| 20 |
+
#if !__has_include(GET_PASS_REGISTRY)
|
| 21 |
+
#error "must provide <Target>PassRegistry.def"
|
| 22 |
+
#endif
|
| 23 |
+
|
| 24 |
+
auto *PIC = PB.getPassInstrumentationCallbacks();
|
| 25 |
+
if (PIC) {
|
| 26 |
+
PIC->registerClassToPassNameCallback([this, PIC]() {
|
| 27 |
+
// MSVC requires this to be captured if it's used inside decltype.
|
| 28 |
+
// Other compilers consider it an unused lambda capture.
|
| 29 |
+
(void)this;
|
| 30 |
+
#define ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS) \
|
| 31 |
+
PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
|
| 32 |
+
#define ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS(NAME, CLASS) \
|
| 33 |
+
PIC->addClassToPassName(CLASS, NAME);
|
| 34 |
+
|
| 35 |
+
#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
|
| 36 |
+
ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
|
| 37 |
+
#define MODULE_PASS(NAME, CREATE_PASS) \
|
| 38 |
+
ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
|
| 39 |
+
#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
|
| 40 |
+
ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS(NAME, CLASS)
|
| 41 |
+
#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
|
| 42 |
+
ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
|
| 43 |
+
#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
|
| 44 |
+
ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
|
| 45 |
+
#define FUNCTION_PASS(NAME, CREATE_PASS) \
|
| 46 |
+
ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
|
| 47 |
+
#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
|
| 48 |
+
ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS(NAME, CLASS)
|
| 49 |
+
#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
|
| 50 |
+
ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
|
| 51 |
+
#define LOOP_PASS(NAME, CREATE_PASS) \
|
| 52 |
+
ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
|
| 53 |
+
#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
|
| 54 |
+
ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
|
| 55 |
+
#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) \
|
| 56 |
+
ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
|
| 57 |
+
#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
|
| 58 |
+
PARAMS) \
|
| 59 |
+
ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS(NAME, CLASS)
|
| 60 |
+
#include GET_PASS_REGISTRY
|
| 61 |
+
#undef MODULE_ANALYSIS
|
| 62 |
+
#undef MODULE_PASS
|
| 63 |
+
#undef MODULE_PASS_WITH_PARAMS
|
| 64 |
+
#undef FUNCTION_ANALYSIS
|
| 65 |
+
#undef FUNCTION_ALIAS_ANALYSIS
|
| 66 |
+
#undef FUNCTION_PASS
|
| 67 |
+
#undef FUNCTION_PASS_WITH_PARAMS
|
| 68 |
+
#undef LOOP_ANALYSIS
|
| 69 |
+
#undef LOOP_PASS
|
| 70 |
+
#undef MACHINE_FUNCTION_ANALYSIS
|
| 71 |
+
#undef MACHINE_FUNCTION_PASS
|
| 72 |
+
#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
|
| 73 |
+
#undef ADD_CLASS_PASS_TO_PASS_NAME
|
| 74 |
+
#undef ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS
|
| 75 |
+
});
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
#define ADD_PASS(NAME, CREATE_PASS) \
|
| 79 |
+
if (Name == NAME) { \
|
| 80 |
+
PM.addPass(CREATE_PASS); \
|
| 81 |
+
return true; \
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
#define ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \
|
| 85 |
+
if (PassBuilder::checkParametrizedPassName(Name, NAME)) { \
|
| 86 |
+
auto Params = PassBuilder::parsePassParameters(PARSER, Name, NAME); \
|
| 87 |
+
if (!Params) { \
|
| 88 |
+
errs() << NAME ": " << toString(Params.takeError()) << '\n'; \
|
| 89 |
+
return false; \
|
| 90 |
+
} \
|
| 91 |
+
PM.addPass(CREATE_PASS(Params.get())); \
|
| 92 |
+
return true; \
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
PB.registerPipelineParsingCallback([=](StringRef Name, ModulePassManager &PM,
|
| 96 |
+
ArrayRef<PassBuilder::PipelineElement>) {
|
| 97 |
+
#define MODULE_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
|
| 98 |
+
#include GET_PASS_REGISTRY
|
| 99 |
+
#undef MODULE_PASS
|
| 100 |
+
return false;
|
| 101 |
+
});
|
| 102 |
+
|
| 103 |
+
PB.registerPipelineParsingCallback([=](StringRef Name, ModulePassManager &PM,
|
| 104 |
+
ArrayRef<PassBuilder::PipelineElement>) {
|
| 105 |
+
#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
|
| 106 |
+
ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)
|
| 107 |
+
#include GET_PASS_REGISTRY
|
| 108 |
+
#undef MODULE_PASS_WITH_PARAMS
|
| 109 |
+
return false;
|
| 110 |
+
});
|
| 111 |
+
|
| 112 |
+
PB.registerPipelineParsingCallback([=](StringRef Name, FunctionPassManager &PM,
|
| 113 |
+
ArrayRef<PassBuilder::PipelineElement>) {
|
| 114 |
+
#define FUNCTION_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
|
| 115 |
+
#include GET_PASS_REGISTRY
|
| 116 |
+
#undef FUNCTION_PASS
|
| 117 |
+
return false;
|
| 118 |
+
});
|
| 119 |
+
|
| 120 |
+
PB.registerPipelineParsingCallback([=](StringRef Name, FunctionPassManager &PM,
|
| 121 |
+
ArrayRef<PassBuilder::PipelineElement>) {
|
| 122 |
+
#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
|
| 123 |
+
ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)
|
| 124 |
+
#include GET_PASS_REGISTRY
|
| 125 |
+
#undef FUNCTION_PASS_WITH_PARAMS
|
| 126 |
+
return false;
|
| 127 |
+
});
|
| 128 |
+
|
| 129 |
+
PB.registerPipelineParsingCallback([=](StringRef Name, LoopPassManager &PM,
|
| 130 |
+
ArrayRef<PassBuilder::PipelineElement>) {
|
| 131 |
+
#define LOOP_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
|
| 132 |
+
#include GET_PASS_REGISTRY
|
| 133 |
+
return false;
|
| 134 |
+
});
|
| 135 |
+
|
| 136 |
+
PB.registerPipelineParsingCallback([=](StringRef Name,
|
| 137 |
+
MachineFunctionPassManager &PM,
|
| 138 |
+
ArrayRef<PassBuilder::PipelineElement>) {
|
| 139 |
+
#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
|
| 140 |
+
#include GET_PASS_REGISTRY
|
| 141 |
+
return false;
|
| 142 |
+
});
|
| 143 |
+
|
| 144 |
+
PB.registerPipelineParsingCallback([=](StringRef Name, FunctionPassManager &PM,
|
| 145 |
+
ArrayRef<PassBuilder::PipelineElement>) {
|
| 146 |
+
#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
|
| 147 |
+
PARAMS) \
|
| 148 |
+
ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)
|
| 149 |
+
#include GET_PASS_REGISTRY
|
| 150 |
+
#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
|
| 151 |
+
return false;
|
| 152 |
+
});
|
| 153 |
+
|
| 154 |
+
#undef ADD_PASS
|
| 155 |
+
#undef ADD_PASS_WITH_PARAMS
|
| 156 |
+
|
| 157 |
+
PB.registerAnalysisRegistrationCallback([](ModuleAnalysisManager &AM) {
|
| 158 |
+
#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
|
| 159 |
+
AM.registerPass([&] { return CREATE_PASS; });
|
| 160 |
+
#include GET_PASS_REGISTRY
|
| 161 |
+
#undef MODULE_ANALYSIS
|
| 162 |
+
});
|
| 163 |
+
|
| 164 |
+
PB.registerAnalysisRegistrationCallback([](FunctionAnalysisManager &AM) {
|
| 165 |
+
#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
|
| 166 |
+
AM.registerPass([&] { return CREATE_PASS; });
|
| 167 |
+
#include GET_PASS_REGISTRY
|
| 168 |
+
#undef FUNCTION_ANALYSIS
|
| 169 |
+
});
|
| 170 |
+
|
| 171 |
+
PB.registerParseAACallback([](StringRef Name, AAManager &AM) {
|
| 172 |
+
#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
|
| 173 |
+
if (Name == NAME) { \
|
| 174 |
+
AM.registerFunctionAnalysis< \
|
| 175 |
+
std::remove_reference_t<decltype(CREATE_PASS)>>(); \
|
| 176 |
+
return true; \
|
| 177 |
+
}
|
| 178 |
+
#include GET_PASS_REGISTRY
|
| 179 |
+
#undef FUNCTION_ALIAS_ANALYSIS
|
| 180 |
+
return false;
|
| 181 |
+
});
|
| 182 |
+
|
| 183 |
+
PB.registerAnalysisRegistrationCallback([](LoopAnalysisManager &AM) {
|
| 184 |
+
#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
|
| 185 |
+
AM.registerPass([&] { return CREATE_PASS; });
|
| 186 |
+
#include GET_PASS_REGISTRY
|
| 187 |
+
#undef LOOP_ANALYSIS
|
| 188 |
+
});
|
| 189 |
+
|
| 190 |
+
PB.registerAnalysisRegistrationCallback([](MachineFunctionAnalysisManager &AM) {
|
| 191 |
+
#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
|
| 192 |
+
AM.registerPass([&] { return CREATE_PASS; });
|
| 193 |
+
#include GET_PASS_REGISTRY
|
| 194 |
+
#undef MACHINE_FUNCTION_ANALYSIS
|
| 195 |
+
});
|
| 196 |
+
|
| 197 |
+
#undef GET_PASS_REGISTRY
|
| 198 |
+
#endif // GET_PASS_REGISTRY
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/CtxInstrContextNode.h
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===--- CtxInstrContextNode.h - Contextual Profile Node --------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//==============================================================================
|
| 9 |
+
//
|
| 10 |
+
// NOTE!
|
| 11 |
+
// llvm/include/llvm/ProfileData/CtxInstrContextNode.h and
|
| 12 |
+
// compiler-rt/lib/ctx_profile/CtxInstrContextNode.h
|
| 13 |
+
// must be exact copies of each other.
|
| 14 |
+
//
|
| 15 |
+
// compiler-rt creates these objects as part of the instrumentation runtime for
|
| 16 |
+
// contextual profiling. LLVM only consumes them to convert a contextual tree
|
| 17 |
+
// to a bitstream.
|
| 18 |
+
//
|
| 19 |
+
//==============================================================================
|
| 20 |
+
|
| 21 |
+
/// The contextual profile is a directed tree where each node has one parent. A
|
| 22 |
+
/// node (ContextNode) corresponds to a function activation. The root of the
|
| 23 |
+
/// tree is at a function that was marked as entrypoint to the compiler. A node
|
| 24 |
+
/// stores counter values for edges and a vector of subcontexts. These are the
|
| 25 |
+
/// contexts of callees. The index in the subcontext vector corresponds to the
|
| 26 |
+
/// index of the callsite (as was instrumented via llvm.instrprof.callsite). At
|
| 27 |
+
/// that index we find a linked list, potentially empty, of ContextNodes. Direct
|
| 28 |
+
/// calls will have 0 or 1 values in the linked list, but indirect callsites may
|
| 29 |
+
/// have more.
|
| 30 |
+
///
|
| 31 |
+
/// The ContextNode has a fixed sized header describing it - the GUID of the
|
| 32 |
+
/// function, the size of the counter and callsite vectors. It is also an
|
| 33 |
+
/// (intrusive) linked list for the purposes of the indirect call case above.
|
| 34 |
+
///
|
| 35 |
+
/// Allocation is expected to happen on an Arena. The allocation lays out inline
|
| 36 |
+
/// the counter and subcontexts vectors. The class offers APIs to correctly
|
| 37 |
+
/// reference the latter.
|
| 38 |
+
///
|
| 39 |
+
/// The layout is as follows:
|
| 40 |
+
///
|
| 41 |
+
/// [[declared fields][counters vector][vector of ptrs to subcontexts]]
|
| 42 |
+
///
|
| 43 |
+
/// See also documentation on the counters and subContexts members below.
|
| 44 |
+
///
|
| 45 |
+
/// The structure of the ContextNode is known to LLVM, because LLVM needs to:
|
| 46 |
+
/// (1) increment counts, and
|
| 47 |
+
/// (2) form a GEP for the position in the subcontext list of a callsite
|
| 48 |
+
/// This means changes to LLVM contextual profile lowering and changes here
|
| 49 |
+
/// must be coupled.
|
| 50 |
+
/// Note: the header content isn't interesting to LLVM (other than its size)
|
| 51 |
+
///
|
| 52 |
+
/// Part of contextual collection is the notion of "scratch contexts". These are
|
| 53 |
+
/// buffers that are "large enough" to allow for memory-safe acceses during
|
| 54 |
+
/// counter increments - meaning the counter increment code in LLVM doesn't need
|
| 55 |
+
/// to be concerned with memory safety. Their subcontexts never get populated,
|
| 56 |
+
/// though. The runtime code here produces and recognizes them.
|
| 57 |
+
|
| 58 |
+
#ifndef LLVM_PROFILEDATA_CTXINSTRCONTEXTNODE_H
|
| 59 |
+
#define LLVM_PROFILEDATA_CTXINSTRCONTEXTNODE_H
|
| 60 |
+
|
| 61 |
+
#include <stdint.h>
|
| 62 |
+
#include <stdlib.h>
|
| 63 |
+
|
| 64 |
+
namespace llvm {
|
| 65 |
+
namespace ctx_profile {
|
| 66 |
+
using GUID = uint64_t;
|
| 67 |
+
|
| 68 |
+
class ContextNode final {
|
| 69 |
+
const GUID Guid;
|
| 70 |
+
ContextNode *const Next;
|
| 71 |
+
const uint32_t NumCounters;
|
| 72 |
+
const uint32_t NumCallsites;
|
| 73 |
+
|
| 74 |
+
public:
|
| 75 |
+
ContextNode(GUID Guid, uint32_t NumCounters, uint32_t NumCallsites,
|
| 76 |
+
ContextNode *Next = nullptr)
|
| 77 |
+
: Guid(Guid), Next(Next), NumCounters(NumCounters),
|
| 78 |
+
NumCallsites(NumCallsites) {}
|
| 79 |
+
|
| 80 |
+
static inline size_t getAllocSize(uint32_t NumCounters,
|
| 81 |
+
uint32_t NumCallsites) {
|
| 82 |
+
return sizeof(ContextNode) + sizeof(uint64_t) * NumCounters +
|
| 83 |
+
sizeof(ContextNode *) * NumCallsites;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
// The counters vector starts right after the static header.
|
| 87 |
+
uint64_t *counters() {
|
| 88 |
+
ContextNode *addr_after = &(this[1]);
|
| 89 |
+
return reinterpret_cast<uint64_t *>(addr_after);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
uint32_t counters_size() const { return NumCounters; }
|
| 93 |
+
uint32_t callsites_size() const { return NumCallsites; }
|
| 94 |
+
|
| 95 |
+
const uint64_t *counters() const {
|
| 96 |
+
return const_cast<ContextNode *>(this)->counters();
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
// The subcontexts vector starts right after the end of the counters vector.
|
| 100 |
+
ContextNode **subContexts() {
|
| 101 |
+
return reinterpret_cast<ContextNode **>(&(counters()[NumCounters]));
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
ContextNode *const *subContexts() const {
|
| 105 |
+
return const_cast<ContextNode *>(this)->subContexts();
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
GUID guid() const { return Guid; }
|
| 109 |
+
ContextNode *next() const { return Next; }
|
| 110 |
+
|
| 111 |
+
size_t size() const { return getAllocSize(NumCounters, NumCallsites); }
|
| 112 |
+
|
| 113 |
+
uint64_t entrycount() const { return counters()[0]; }
|
| 114 |
+
};
|
| 115 |
+
|
| 116 |
+
/// The internal structure of FunctionData. This makes sure that changes to
|
| 117 |
+
/// the fields of FunctionData either get automatically captured on the llvm
|
| 118 |
+
/// side, or force a manual corresponding update.
|
| 119 |
+
///
|
| 120 |
+
/// The macro arguments (see CtxInstrProfiling.h for example):
|
| 121 |
+
///
|
| 122 |
+
/// PTRDECL is a macro taking 2 parameters: a type and the name of the field.
|
| 123 |
+
/// The field is a pointer of that type;
|
| 124 |
+
///
|
| 125 |
+
/// VOLATILE_PTRDECL is the same as above, but for volatile pointers;
|
| 126 |
+
///
|
| 127 |
+
/// MUTEXDECL takes one parameter, the name of a field that is a mutex.
|
| 128 |
+
#define CTXPROF_FUNCTION_DATA(PTRDECL, CONTEXT_PTR, VOLATILE_PTRDECL, \
|
| 129 |
+
MUTEXDECL) \
|
| 130 |
+
PTRDECL(FunctionData, Next) \
|
| 131 |
+
VOLATILE_PTRDECL(void, EntryAddress) \
|
| 132 |
+
CONTEXT_PTR \
|
| 133 |
+
VOLATILE_PTRDECL(ContextNode, FlatCtx) \
|
| 134 |
+
MUTEXDECL(Mutex)
|
| 135 |
+
|
| 136 |
+
/// Abstraction for the parameter passed to `__llvm_ctx_profile_fetch`.
|
| 137 |
+
/// `startContextSection` is called before any context roots are sent for
|
| 138 |
+
/// writing. Then one or more `writeContextual` calls are made; finally,
|
| 139 |
+
/// `endContextSection` is called.
|
| 140 |
+
class ProfileWriter {
|
| 141 |
+
public:
|
| 142 |
+
virtual void startContextSection() = 0;
|
| 143 |
+
virtual void writeContextual(const ctx_profile::ContextNode &RootNode,
|
| 144 |
+
const ctx_profile::ContextNode *Unhandled,
|
| 145 |
+
uint64_t TotalRootEntryCount) = 0;
|
| 146 |
+
virtual void endContextSection() = 0;
|
| 147 |
+
|
| 148 |
+
virtual void startFlatSection() = 0;
|
| 149 |
+
virtual void writeFlat(ctx_profile::GUID Guid, const uint64_t *Buffer,
|
| 150 |
+
size_t BufferSize) = 0;
|
| 151 |
+
virtual void endFlatSection() = 0;
|
| 152 |
+
|
| 153 |
+
virtual ~ProfileWriter() = default;
|
| 154 |
+
};
|
| 155 |
+
} // namespace ctx_profile
|
| 156 |
+
} // namespace llvm
|
| 157 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/DataAccessProf.h
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- DataAccessProf.h - Data access profile format support ---------*- C++
|
| 2 |
+
//-*-===//
|
| 3 |
+
//
|
| 4 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 5 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 6 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 7 |
+
//
|
| 8 |
+
//===----------------------------------------------------------------------===//
|
| 9 |
+
//
|
| 10 |
+
// This file contains support to construct and use data access profiles.
|
| 11 |
+
//
|
| 12 |
+
// For the original RFC of this pass please see
|
| 13 |
+
// https://discourse.llvm.org/t/rfc-profile-guided-static-data-partitioning/83744
|
| 14 |
+
//
|
| 15 |
+
//===----------------------------------------------------------------------===//
|
| 16 |
+
|
| 17 |
+
#ifndef LLVM_PROFILEDATA_DATAACCESSPROF_H_
|
| 18 |
+
#define LLVM_PROFILEDATA_DATAACCESSPROF_H_
|
| 19 |
+
|
| 20 |
+
#include "llvm/ADT/DenseMapInfoVariant.h"
|
| 21 |
+
#include "llvm/ADT/MapVector.h"
|
| 22 |
+
#include "llvm/ADT/SetVector.h"
|
| 23 |
+
#include "llvm/ADT/SmallVector.h"
|
| 24 |
+
#include "llvm/ADT/StringRef.h"
|
| 25 |
+
#include "llvm/ProfileData/InstrProf.h"
|
| 26 |
+
#include "llvm/Support/Allocator.h"
|
| 27 |
+
#include "llvm/Support/Error.h"
|
| 28 |
+
#include "llvm/Support/StringSaver.h"
|
| 29 |
+
|
| 30 |
+
#include <cstdint>
|
| 31 |
+
#include <optional>
|
| 32 |
+
#include <variant>
|
| 33 |
+
|
| 34 |
+
namespace llvm {
|
| 35 |
+
|
| 36 |
+
namespace memprof {
|
| 37 |
+
|
| 38 |
+
/// The location of data in the source code. Used by profile lookup API.
|
| 39 |
+
struct SourceLocation {
|
| 40 |
+
SourceLocation(StringRef FileNameRef, uint32_t Line)
|
| 41 |
+
: FileName(FileNameRef.str()), Line(Line) {}
|
| 42 |
+
|
| 43 |
+
// Empty constructor is used in yaml conversion.
|
| 44 |
+
SourceLocation() {}
|
| 45 |
+
/// The filename where the data is located.
|
| 46 |
+
std::string FileName;
|
| 47 |
+
/// The line number in the source code.
|
| 48 |
+
uint32_t Line;
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
namespace internal {
|
| 52 |
+
|
| 53 |
+
// Conceptually similar to SourceLocation except that FileNames are StringRef of
|
| 54 |
+
// which strings are owned by `DataAccessProfData`. Used by `DataAccessProfData`
|
| 55 |
+
// to represent data locations internally.
|
| 56 |
+
struct SourceLocationRef {
|
| 57 |
+
SourceLocationRef(StringRef FileNameRef, uint32_t Line)
|
| 58 |
+
: FileName(FileNameRef), Line(Line) {}
|
| 59 |
+
// The filename where the data is located.
|
| 60 |
+
StringRef FileName;
|
| 61 |
+
// The line number in the source code.
|
| 62 |
+
uint32_t Line;
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
// The data access profiles for a symbol. Used by `DataAccessProfData`
|
| 66 |
+
// to represent records internally.
|
| 67 |
+
struct DataAccessProfRecordRef {
|
| 68 |
+
DataAccessProfRecordRef(uint64_t SymbolID, uint64_t AccessCount,
|
| 69 |
+
bool IsStringLiteral)
|
| 70 |
+
: SymbolID(SymbolID), AccessCount(AccessCount),
|
| 71 |
+
IsStringLiteral(IsStringLiteral) {}
|
| 72 |
+
|
| 73 |
+
// Represents a data symbol. The semantic comes in two forms: a symbol index
|
| 74 |
+
// for symbol name if `IsStringLiteral` is false, or the hash of a string
|
| 75 |
+
// content if `IsStringLiteral` is true. For most of the symbolizable static
|
| 76 |
+
// data, the mangled symbol names remain stable relative to the source code
|
| 77 |
+
// and therefore used to identify symbols across binary releases. String
|
| 78 |
+
// literals have unstable name patterns like `.str.N[.llvm.hash]`, so we use
|
| 79 |
+
// the content hash instead. This is a required field.
|
| 80 |
+
uint64_t SymbolID;
|
| 81 |
+
|
| 82 |
+
// The access count of symbol. Required.
|
| 83 |
+
uint64_t AccessCount;
|
| 84 |
+
|
| 85 |
+
// True iff this is a record for string literal (symbols with name pattern
|
| 86 |
+
// `.str.*` in the symbol table). Required.
|
| 87 |
+
bool IsStringLiteral;
|
| 88 |
+
|
| 89 |
+
// The locations of data in the source code. Optional.
|
| 90 |
+
llvm::SmallVector<SourceLocationRef, 0> Locations;
|
| 91 |
+
};
|
| 92 |
+
} // namespace internal
|
| 93 |
+
|
| 94 |
+
// SymbolID is either a string representing symbol name if the symbol has
|
| 95 |
+
// stable mangled name relative to source code, or a uint64_t representing the
|
| 96 |
+
// content hash of a string literal (with unstable name patterns like
|
| 97 |
+
// `.str.N[.llvm.hash]`). The StringRef is owned by the class's saver object.
|
| 98 |
+
using SymbolHandleRef = std::variant<StringRef, uint64_t>;
|
| 99 |
+
|
| 100 |
+
// The senamtic is the same as `SymbolHandleRef` above. The strings are owned.
|
| 101 |
+
using SymbolHandle = std::variant<std::string, uint64_t>;
|
| 102 |
+
|
| 103 |
+
/// The data access profiles for a symbol.
|
| 104 |
+
struct DataAccessProfRecord {
|
| 105 |
+
public:
|
| 106 |
+
DataAccessProfRecord(SymbolHandleRef SymHandleRef, uint64_t AccessCount,
|
| 107 |
+
ArrayRef<internal::SourceLocationRef> LocRefs)
|
| 108 |
+
: AccessCount(AccessCount) {
|
| 109 |
+
if (std::holds_alternative<StringRef>(SymHandleRef)) {
|
| 110 |
+
SymHandle = std::get<StringRef>(SymHandleRef).str();
|
| 111 |
+
} else
|
| 112 |
+
SymHandle = std::get<uint64_t>(SymHandleRef);
|
| 113 |
+
|
| 114 |
+
for (auto Loc : LocRefs)
|
| 115 |
+
Locations.emplace_back(Loc.FileName, Loc.Line);
|
| 116 |
+
}
|
| 117 |
+
// Empty constructor is used in yaml conversion.
|
| 118 |
+
DataAccessProfRecord() : AccessCount(0) {}
|
| 119 |
+
SymbolHandle SymHandle;
|
| 120 |
+
uint64_t AccessCount;
|
| 121 |
+
// The locations of data in the source code. Optional.
|
| 122 |
+
SmallVector<SourceLocation> Locations;
|
| 123 |
+
};
|
| 124 |
+
|
| 125 |
+
/// Encapsulates the data access profile data and the methods to operate on
|
| 126 |
+
/// it. This class provides profile look-up, serialization and
|
| 127 |
+
/// deserialization.
|
| 128 |
+
class DataAccessProfData {
|
| 129 |
+
public:
|
| 130 |
+
// Use MapVector to keep input order of strings for serialization and
|
| 131 |
+
// deserialization.
|
| 132 |
+
using StringToIndexMap = llvm::MapVector<StringRef, uint64_t>;
|
| 133 |
+
|
| 134 |
+
DataAccessProfData() : Saver(Allocator) {}
|
| 135 |
+
|
| 136 |
+
/// Serialize profile data to the output stream.
|
| 137 |
+
/// Storage layout:
|
| 138 |
+
/// - Serialized strings.
|
| 139 |
+
/// - The encoded hashes.
|
| 140 |
+
/// - Records.
|
| 141 |
+
Error serialize(ProfOStream &OS) const;
|
| 142 |
+
|
| 143 |
+
/// Deserialize this class from the given buffer.
|
| 144 |
+
Error deserialize(const unsigned char *&Ptr);
|
| 145 |
+
|
| 146 |
+
/// Returns a profile record for \p SymbolID, or std::nullopt if there
|
| 147 |
+
/// isn't a record. Internally, this function will canonicalize the symbol
|
| 148 |
+
/// name before the lookup.
|
| 149 |
+
std::optional<DataAccessProfRecord>
|
| 150 |
+
getProfileRecord(const SymbolHandleRef SymID) const;
|
| 151 |
+
|
| 152 |
+
/// Returns true if \p SymID is seen in profiled binaries and cold.
|
| 153 |
+
bool isKnownColdSymbol(const SymbolHandleRef SymID) const;
|
| 154 |
+
|
| 155 |
+
/// Methods to set symbolized data access profile. Returns error if
|
| 156 |
+
/// duplicated symbol names or content hashes are seen. The user of this
|
| 157 |
+
/// class should aggregate counters that correspond to the same symbol name
|
| 158 |
+
/// or with the same string literal hash before calling 'set*' methods.
|
| 159 |
+
Error setDataAccessProfile(SymbolHandleRef SymbolID, uint64_t AccessCount);
|
| 160 |
+
/// Similar to the method above, for records with \p Locations representing
|
| 161 |
+
/// the `filename:line` where this symbol shows up. Note because of linker's
|
| 162 |
+
/// merge of identical symbols (e.g., unnamed_addr string literals), one
|
| 163 |
+
/// symbol is likely to have multiple locations.
|
| 164 |
+
Error setDataAccessProfile(SymbolHandleRef SymbolID, uint64_t AccessCount,
|
| 165 |
+
ArrayRef<SourceLocation> Locations);
|
| 166 |
+
/// Add a symbol that's seen in the profiled binary without samples.
|
| 167 |
+
Error addKnownSymbolWithoutSamples(SymbolHandleRef SymbolID);
|
| 168 |
+
|
| 169 |
+
/// The following methods return array reference for various internal data
|
| 170 |
+
/// structures.
|
| 171 |
+
ArrayRef<StringToIndexMap::value_type> getStrToIndexMapRef() const {
|
| 172 |
+
return StrToIndexMap.getArrayRef();
|
| 173 |
+
}
|
| 174 |
+
ArrayRef<
|
| 175 |
+
MapVector<SymbolHandleRef, internal::DataAccessProfRecordRef>::value_type>
|
| 176 |
+
getRecords() const {
|
| 177 |
+
return Records.getArrayRef();
|
| 178 |
+
}
|
| 179 |
+
ArrayRef<StringRef> getKnownColdSymbols() const {
|
| 180 |
+
return KnownColdSymbols.getArrayRef();
|
| 181 |
+
}
|
| 182 |
+
ArrayRef<uint64_t> getKnownColdHashes() const {
|
| 183 |
+
return KnownColdHashes.getArrayRef();
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
private:
|
| 187 |
+
/// Serialize the symbol strings into the output stream.
|
| 188 |
+
Error serializeSymbolsAndFilenames(ProfOStream &OS) const;
|
| 189 |
+
|
| 190 |
+
/// Deserialize the symbol strings from \p Ptr and increment \p Ptr to the
|
| 191 |
+
/// start of the next payload.
|
| 192 |
+
Error deserializeSymbolsAndFilenames(const unsigned char *&Ptr,
|
| 193 |
+
const uint64_t NumSampledSymbols,
|
| 194 |
+
const uint64_t NumColdKnownSymbols);
|
| 195 |
+
|
| 196 |
+
/// Decode the records and increment \p Ptr to the start of the next
|
| 197 |
+
/// payload.
|
| 198 |
+
Error deserializeRecords(const unsigned char *&Ptr);
|
| 199 |
+
|
| 200 |
+
/// A helper function to compute a storage index for \p SymbolID.
|
| 201 |
+
uint64_t getEncodedIndex(const SymbolHandleRef SymbolID) const;
|
| 202 |
+
|
| 203 |
+
// Keeps owned copies of the input strings.
|
| 204 |
+
// NOTE: Keep `Saver` initialized before other class members that reference
|
| 205 |
+
// its string copies and destructed after they are destructed.
|
| 206 |
+
llvm::BumpPtrAllocator Allocator;
|
| 207 |
+
llvm::UniqueStringSaver Saver;
|
| 208 |
+
|
| 209 |
+
// `Records` stores the records.
|
| 210 |
+
MapVector<SymbolHandleRef, internal::DataAccessProfRecordRef> Records;
|
| 211 |
+
|
| 212 |
+
StringToIndexMap StrToIndexMap;
|
| 213 |
+
llvm::SetVector<uint64_t> KnownColdHashes;
|
| 214 |
+
llvm::SetVector<StringRef> KnownColdSymbols;
|
| 215 |
+
};
|
| 216 |
+
|
| 217 |
+
} // namespace memprof
|
| 218 |
+
} // namespace llvm
|
| 219 |
+
|
| 220 |
+
#endif // LLVM_PROFILEDATA_DATAACCESSPROF_H_
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/FunctionId.h
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===--- FunctionId.h - Sample profile function object ----------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
///
|
| 9 |
+
/// \file
|
| 10 |
+
///
|
| 11 |
+
/// Defines FunctionId class.
|
| 12 |
+
///
|
| 13 |
+
//===----------------------------------------------------------------------===//
|
| 14 |
+
|
| 15 |
+
#ifndef LLVM_PROFILEDATA_FUNCTIONID_H
|
| 16 |
+
#define LLVM_PROFILEDATA_FUNCTIONID_H
|
| 17 |
+
|
| 18 |
+
#include "llvm/ADT/DenseMapInfo.h"
|
| 19 |
+
#include "llvm/ADT/Hashing.h"
|
| 20 |
+
#include "llvm/ADT/StringRef.h"
|
| 21 |
+
#include "llvm/Support/MD5.h"
|
| 22 |
+
#include "llvm/Support/raw_ostream.h"
|
| 23 |
+
#include <cstdint>
|
| 24 |
+
|
| 25 |
+
namespace llvm {
|
| 26 |
+
namespace sampleprof {
|
| 27 |
+
|
| 28 |
+
/// This class represents a function that is read from a sample profile. It
|
| 29 |
+
/// comes with two forms: a string or a hash code. The latter form is the 64-bit
|
| 30 |
+
/// MD5 of the function name for efficient storage supported by ExtBinary
|
| 31 |
+
/// profile format, and when reading the profile, this class can represent it
|
| 32 |
+
/// without converting it to a string first.
|
| 33 |
+
/// When representing a hash code, we utilize the LengthOrHashCode field to
|
| 34 |
+
/// store it, and Name is set to null. When representing a string, it is same as
|
| 35 |
+
/// StringRef.
|
| 36 |
+
class FunctionId {
|
| 37 |
+
|
| 38 |
+
const char *Data = nullptr;
|
| 39 |
+
|
| 40 |
+
// Use uint64_t instead of size_t so that it can also hold a MD5 value on
|
| 41 |
+
// 32-bit system.
|
| 42 |
+
uint64_t LengthOrHashCode = 0;
|
| 43 |
+
|
| 44 |
+
/// Extension to memcmp to handle hash code representation. If both are hash
|
| 45 |
+
/// values, Lhs and Rhs are both null, function returns 0 (and needs an extra
|
| 46 |
+
/// comparison using getIntValue). If only one is hash code, it is considered
|
| 47 |
+
/// less than the StringRef one. Otherwise perform normal string comparison.
|
| 48 |
+
static int compareMemory(const char *Lhs, const char *Rhs, uint64_t Length) {
|
| 49 |
+
if (Lhs == Rhs)
|
| 50 |
+
return 0;
|
| 51 |
+
if (!Lhs)
|
| 52 |
+
return -1;
|
| 53 |
+
if (!Rhs)
|
| 54 |
+
return 1;
|
| 55 |
+
return ::memcmp(Lhs, Rhs, (size_t)Length);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
public:
|
| 59 |
+
FunctionId() = default;
|
| 60 |
+
|
| 61 |
+
/// Constructor from a StringRef.
|
| 62 |
+
explicit FunctionId(StringRef Str)
|
| 63 |
+
: Data(Str.data()), LengthOrHashCode(Str.size()) {
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
/// Constructor from a hash code.
|
| 67 |
+
explicit FunctionId(uint64_t HashCode)
|
| 68 |
+
: LengthOrHashCode(HashCode) {
|
| 69 |
+
assert(HashCode != 0);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
/// Check for equality. Similar to StringRef::equals, but will also cover for
|
| 73 |
+
/// the case where one or both are hash codes. Comparing their int values are
|
| 74 |
+
/// sufficient. A hash code FunctionId is considered not equal to a StringRef
|
| 75 |
+
/// FunctionId regardless of actual contents.
|
| 76 |
+
bool equals(const FunctionId &Other) const {
|
| 77 |
+
return LengthOrHashCode == Other.LengthOrHashCode &&
|
| 78 |
+
compareMemory(Data, Other.Data, LengthOrHashCode) == 0;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/// Total order comparison. If both FunctionId are StringRef, this is the same
|
| 82 |
+
/// as StringRef::compare. If one of them is StringRef, it is considered
|
| 83 |
+
/// greater than the hash code FunctionId. Otherwise this is the the same
|
| 84 |
+
/// as comparing their int values.
|
| 85 |
+
int compare(const FunctionId &Other) const {
|
| 86 |
+
auto Res = compareMemory(
|
| 87 |
+
Data, Other.Data, std::min(LengthOrHashCode, Other.LengthOrHashCode));
|
| 88 |
+
if (Res != 0)
|
| 89 |
+
return Res;
|
| 90 |
+
if (LengthOrHashCode == Other.LengthOrHashCode)
|
| 91 |
+
return 0;
|
| 92 |
+
return LengthOrHashCode < Other.LengthOrHashCode ? -1 : 1;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
/// Convert to a string, usually for output purpose. Use caution on return
|
| 96 |
+
/// value's lifetime when converting to StringRef.
|
| 97 |
+
std::string str() const {
|
| 98 |
+
if (Data)
|
| 99 |
+
return std::string(Data, LengthOrHashCode);
|
| 100 |
+
if (LengthOrHashCode != 0)
|
| 101 |
+
return std::to_string(LengthOrHashCode);
|
| 102 |
+
return std::string();
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/// Convert to StringRef. This is only allowed when it is known this object is
|
| 106 |
+
/// representing a StringRef, not a hash code. Calling this function on a hash
|
| 107 |
+
/// code is considered an error.
|
| 108 |
+
StringRef stringRef() const {
|
| 109 |
+
if (Data)
|
| 110 |
+
return StringRef(Data, LengthOrHashCode);
|
| 111 |
+
assert(LengthOrHashCode == 0 &&
|
| 112 |
+
"Cannot convert MD5 FunctionId to StringRef");
|
| 113 |
+
return StringRef();
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
friend raw_ostream &operator<<(raw_ostream &OS, const FunctionId &Obj);
|
| 117 |
+
|
| 118 |
+
/// Get hash code of this object. Returns this object's hash code if it is
|
| 119 |
+
/// already representing one, otherwise returns the MD5 of its string content.
|
| 120 |
+
/// Note that it is not the same as std::hash because we want to keep the
|
| 121 |
+
/// consistency that the same sample profile function in string form or MD5
|
| 122 |
+
/// form has the same hash code.
|
| 123 |
+
uint64_t getHashCode() const {
|
| 124 |
+
if (Data)
|
| 125 |
+
return MD5Hash(StringRef(Data, LengthOrHashCode));
|
| 126 |
+
return LengthOrHashCode;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
bool empty() const { return LengthOrHashCode == 0; }
|
| 130 |
+
|
| 131 |
+
/// Check if this object represents a StringRef, or a hash code.
|
| 132 |
+
bool isStringRef() const { return Data != nullptr; }
|
| 133 |
+
};
|
| 134 |
+
|
| 135 |
+
inline bool operator==(const FunctionId &LHS, const FunctionId &RHS) {
|
| 136 |
+
return LHS.equals(RHS);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
inline bool operator!=(const FunctionId &LHS, const FunctionId &RHS) {
|
| 140 |
+
return !LHS.equals(RHS);
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
inline bool operator<(const FunctionId &LHS, const FunctionId &RHS) {
|
| 144 |
+
return LHS.compare(RHS) < 0;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
inline bool operator<=(const FunctionId &LHS, const FunctionId &RHS) {
|
| 148 |
+
return LHS.compare(RHS) <= 0;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
inline bool operator>(const FunctionId &LHS, const FunctionId &RHS) {
|
| 152 |
+
return LHS.compare(RHS) > 0;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
inline bool operator>=(const FunctionId &LHS, const FunctionId &RHS) {
|
| 156 |
+
return LHS.compare(RHS) >= 0;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
inline raw_ostream &operator<<(raw_ostream &OS, const FunctionId &Obj) {
|
| 160 |
+
if (Obj.Data)
|
| 161 |
+
return OS << StringRef(Obj.Data, Obj.LengthOrHashCode);
|
| 162 |
+
if (Obj.LengthOrHashCode != 0)
|
| 163 |
+
return OS << Obj.LengthOrHashCode;
|
| 164 |
+
return OS;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
inline uint64_t MD5Hash(const FunctionId &Obj) {
|
| 168 |
+
return Obj.getHashCode();
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
inline uint64_t hash_value(const FunctionId &Obj) {
|
| 172 |
+
return Obj.getHashCode();
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
} // end namespace sampleprof
|
| 176 |
+
|
| 177 |
+
/// Template specialization for FunctionId so that it can be used in LLVM map
|
| 178 |
+
/// containers.
|
| 179 |
+
template <> struct DenseMapInfo<sampleprof::FunctionId, void> {
|
| 180 |
+
|
| 181 |
+
static inline sampleprof::FunctionId getEmptyKey() {
|
| 182 |
+
return sampleprof::FunctionId(~0ULL);
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
static inline sampleprof::FunctionId getTombstoneKey() {
|
| 186 |
+
return sampleprof::FunctionId(~1ULL);
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
static unsigned getHashValue(const sampleprof::FunctionId &Val) {
|
| 190 |
+
return Val.getHashCode();
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
static bool isEqual(const sampleprof::FunctionId &LHS,
|
| 194 |
+
const sampleprof::FunctionId &RHS) {
|
| 195 |
+
return LHS == RHS;
|
| 196 |
+
}
|
| 197 |
+
};
|
| 198 |
+
|
| 199 |
+
} // end namespace llvm
|
| 200 |
+
|
| 201 |
+
namespace std {
|
| 202 |
+
|
| 203 |
+
/// Template specialization for FunctionId so that it can be used in STL
|
| 204 |
+
/// containers.
|
| 205 |
+
template <> struct hash<llvm::sampleprof::FunctionId> {
|
| 206 |
+
size_t operator()(const llvm::sampleprof::FunctionId &Val) const {
|
| 207 |
+
return Val.getHashCode();
|
| 208 |
+
}
|
| 209 |
+
};
|
| 210 |
+
|
| 211 |
+
} // end namespace std
|
| 212 |
+
|
| 213 |
+
#endif // LLVM_PROFILEDATA_FUNCTIONID_H
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/GCOV.h
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- GCOV.h - LLVM coverage tool ------------------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This header provides the interface to read and write coverage files that
|
| 10 |
+
// use 'gcov' format.
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#ifndef LLVM_PROFILEDATA_GCOV_H
|
| 15 |
+
#define LLVM_PROFILEDATA_GCOV_H
|
| 16 |
+
|
| 17 |
+
#include "llvm/ADT/DenseSet.h"
|
| 18 |
+
#include "llvm/ADT/SmallString.h"
|
| 19 |
+
#include "llvm/ADT/SmallVector.h"
|
| 20 |
+
#include "llvm/ADT/StringMap.h"
|
| 21 |
+
#include "llvm/ADT/StringRef.h"
|
| 22 |
+
#include "llvm/ADT/iterator.h"
|
| 23 |
+
#include "llvm/ADT/iterator_range.h"
|
| 24 |
+
#include "llvm/Support/DataExtractor.h"
|
| 25 |
+
#include "llvm/Support/MemoryBuffer.h"
|
| 26 |
+
#include "llvm/Support/raw_ostream.h"
|
| 27 |
+
#include <algorithm>
|
| 28 |
+
#include <cstddef>
|
| 29 |
+
#include <cstdint>
|
| 30 |
+
#include <map>
|
| 31 |
+
#include <memory>
|
| 32 |
+
#include <string>
|
| 33 |
+
#include <utility>
|
| 34 |
+
|
| 35 |
+
namespace llvm {
|
| 36 |
+
|
| 37 |
+
class GCOVFunction;
|
| 38 |
+
class GCOVBlock;
|
| 39 |
+
|
| 40 |
+
namespace GCOV {
|
| 41 |
+
|
| 42 |
+
enum GCOVVersion { V304, V407, V408, V800, V900, V1200 };
|
| 43 |
+
|
| 44 |
+
/// A struct for passing gcov options between functions.
|
| 45 |
+
struct Options {
|
| 46 |
+
Options(bool A, bool B, bool C, bool F, bool P, bool U, bool I, bool L,
|
| 47 |
+
bool M, bool N, bool R, bool T, bool X, std::string SourcePrefix)
|
| 48 |
+
: AllBlocks(A), BranchInfo(B), BranchCount(C), FuncCoverage(F),
|
| 49 |
+
PreservePaths(P), UncondBranch(U), Intermediate(I), LongFileNames(L),
|
| 50 |
+
Demangle(M), NoOutput(N), RelativeOnly(R), UseStdout(T),
|
| 51 |
+
HashFilenames(X), SourcePrefix(std::move(SourcePrefix)) {}
|
| 52 |
+
|
| 53 |
+
bool AllBlocks;
|
| 54 |
+
bool BranchInfo;
|
| 55 |
+
bool BranchCount;
|
| 56 |
+
bool FuncCoverage;
|
| 57 |
+
bool PreservePaths;
|
| 58 |
+
bool UncondBranch;
|
| 59 |
+
bool Intermediate;
|
| 60 |
+
bool LongFileNames;
|
| 61 |
+
bool Demangle;
|
| 62 |
+
bool NoOutput;
|
| 63 |
+
bool RelativeOnly;
|
| 64 |
+
bool UseStdout;
|
| 65 |
+
bool HashFilenames;
|
| 66 |
+
std::string SourcePrefix;
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
} // end namespace GCOV
|
| 70 |
+
|
| 71 |
+
/// GCOVBuffer - A wrapper around MemoryBuffer to provide GCOV specific
|
| 72 |
+
/// read operations.
|
| 73 |
+
class GCOVBuffer {
|
| 74 |
+
public:
|
| 75 |
+
GCOVBuffer(MemoryBuffer *B) : Buffer(B) {}
|
| 76 |
+
~GCOVBuffer() { consumeError(cursor.takeError()); }
|
| 77 |
+
|
| 78 |
+
/// readGCNOFormat - Check GCNO signature is valid at the beginning of buffer.
|
| 79 |
+
bool readGCNOFormat() {
|
| 80 |
+
StringRef buf = Buffer->getBuffer();
|
| 81 |
+
StringRef magic = buf.substr(0, 4);
|
| 82 |
+
if (magic == "gcno") {
|
| 83 |
+
de = DataExtractor(buf.substr(4), false, 0);
|
| 84 |
+
} else if (magic == "oncg") {
|
| 85 |
+
de = DataExtractor(buf.substr(4), true, 0);
|
| 86 |
+
} else {
|
| 87 |
+
errs() << "unexpected magic: " << magic << "\n";
|
| 88 |
+
return false;
|
| 89 |
+
}
|
| 90 |
+
return true;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/// readGCDAFormat - Check GCDA signature is valid at the beginning of buffer.
|
| 94 |
+
bool readGCDAFormat() {
|
| 95 |
+
StringRef buf = Buffer->getBuffer();
|
| 96 |
+
StringRef magic = buf.substr(0, 4);
|
| 97 |
+
if (magic == "gcda") {
|
| 98 |
+
de = DataExtractor(buf.substr(4), false, 0);
|
| 99 |
+
} else if (magic == "adcg") {
|
| 100 |
+
de = DataExtractor(buf.substr(4), true, 0);
|
| 101 |
+
} else {
|
| 102 |
+
return false;
|
| 103 |
+
}
|
| 104 |
+
return true;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/// readGCOVVersion - Read GCOV version.
|
| 108 |
+
bool readGCOVVersion(GCOV::GCOVVersion &version) {
|
| 109 |
+
std::string str(de.getBytes(cursor, 4));
|
| 110 |
+
if (str.size() != 4)
|
| 111 |
+
return false;
|
| 112 |
+
if (de.isLittleEndian())
|
| 113 |
+
std::reverse(str.begin(), str.end());
|
| 114 |
+
int ver = str[0] >= 'A'
|
| 115 |
+
? (str[0] - 'A') * 100 + (str[1] - '0') * 10 + str[2] - '0'
|
| 116 |
+
: (str[0] - '0') * 10 + str[2] - '0';
|
| 117 |
+
if (ver >= 120) {
|
| 118 |
+
this->version = version = GCOV::V1200;
|
| 119 |
+
return true;
|
| 120 |
+
} else if (ver >= 90) {
|
| 121 |
+
// PR gcov-profile/84846, r269678
|
| 122 |
+
this->version = version = GCOV::V900;
|
| 123 |
+
return true;
|
| 124 |
+
} else if (ver >= 80) {
|
| 125 |
+
// PR gcov-profile/48463
|
| 126 |
+
this->version = version = GCOV::V800;
|
| 127 |
+
return true;
|
| 128 |
+
} else if (ver >= 48) {
|
| 129 |
+
// r189778: the exit block moved from the last to the second.
|
| 130 |
+
this->version = version = GCOV::V408;
|
| 131 |
+
return true;
|
| 132 |
+
} else if (ver >= 47) {
|
| 133 |
+
// r173147: split checksum into cfg checksum and line checksum.
|
| 134 |
+
this->version = version = GCOV::V407;
|
| 135 |
+
return true;
|
| 136 |
+
} else if (ver >= 34) {
|
| 137 |
+
this->version = version = GCOV::V304;
|
| 138 |
+
return true;
|
| 139 |
+
}
|
| 140 |
+
errs() << "unexpected version: " << str << "\n";
|
| 141 |
+
return false;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
uint32_t getWord() { return de.getU32(cursor); }
|
| 145 |
+
StringRef getString() {
|
| 146 |
+
uint32_t len;
|
| 147 |
+
if (!readInt(len) || len == 0)
|
| 148 |
+
return {};
|
| 149 |
+
return de.getBytes(cursor, len * 4).split('\0').first;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
bool readInt(uint32_t &Val) {
|
| 153 |
+
if (cursor.tell() + 4 > de.size()) {
|
| 154 |
+
Val = 0;
|
| 155 |
+
errs() << "unexpected end of memory buffer: " << cursor.tell() << "\n";
|
| 156 |
+
return false;
|
| 157 |
+
}
|
| 158 |
+
Val = de.getU32(cursor);
|
| 159 |
+
return true;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
bool readInt64(uint64_t &Val) {
|
| 163 |
+
uint32_t Lo, Hi;
|
| 164 |
+
if (!readInt(Lo) || !readInt(Hi))
|
| 165 |
+
return false;
|
| 166 |
+
Val = ((uint64_t)Hi << 32) | Lo;
|
| 167 |
+
return true;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
bool readString(StringRef &str) {
|
| 171 |
+
uint32_t len;
|
| 172 |
+
if (!readInt(len) || len == 0)
|
| 173 |
+
return false;
|
| 174 |
+
if (version >= GCOV::V1200)
|
| 175 |
+
str = de.getBytes(cursor, len).drop_back();
|
| 176 |
+
else
|
| 177 |
+
str = de.getBytes(cursor, len * 4).split('\0').first;
|
| 178 |
+
return bool(cursor);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
DataExtractor de{ArrayRef<uint8_t>{}, false, 0};
|
| 182 |
+
DataExtractor::Cursor cursor{0};
|
| 183 |
+
|
| 184 |
+
private:
|
| 185 |
+
MemoryBuffer *Buffer;
|
| 186 |
+
GCOV::GCOVVersion version{};
|
| 187 |
+
};
|
| 188 |
+
|
| 189 |
+
/// GCOVFile - Collects coverage information for one pair of coverage file
|
| 190 |
+
/// (.gcno and .gcda).
|
| 191 |
+
class GCOVFile {
|
| 192 |
+
public:
|
| 193 |
+
GCOVFile() = default;
|
| 194 |
+
|
| 195 |
+
bool readGCNO(GCOVBuffer &Buffer);
|
| 196 |
+
bool readGCDA(GCOVBuffer &Buffer);
|
| 197 |
+
GCOV::GCOVVersion getVersion() const { return version; }
|
| 198 |
+
void print(raw_ostream &OS) const;
|
| 199 |
+
void dump() const;
|
| 200 |
+
|
| 201 |
+
std::vector<std::string> filenames;
|
| 202 |
+
StringMap<unsigned> filenameToIdx;
|
| 203 |
+
|
| 204 |
+
public:
|
| 205 |
+
bool GCNOInitialized = false;
|
| 206 |
+
GCOV::GCOVVersion version{};
|
| 207 |
+
uint32_t checksum = 0;
|
| 208 |
+
StringRef cwd;
|
| 209 |
+
SmallVector<std::unique_ptr<GCOVFunction>, 16> functions;
|
| 210 |
+
std::map<uint32_t, GCOVFunction *> identToFunction;
|
| 211 |
+
uint32_t runCount = 0;
|
| 212 |
+
uint32_t programCount = 0;
|
| 213 |
+
|
| 214 |
+
using iterator = pointee_iterator<
|
| 215 |
+
SmallVectorImpl<std::unique_ptr<GCOVFunction>>::const_iterator>;
|
| 216 |
+
iterator begin() const { return iterator(functions.begin()); }
|
| 217 |
+
iterator end() const { return iterator(functions.end()); }
|
| 218 |
+
|
| 219 |
+
private:
|
| 220 |
+
unsigned addNormalizedPathToMap(StringRef filename);
|
| 221 |
+
};
|
| 222 |
+
|
| 223 |
+
struct GCOVArc {
|
| 224 |
+
GCOVArc(GCOVBlock &src, GCOVBlock &dst, uint32_t flags)
|
| 225 |
+
: src(src), dst(dst), flags(flags) {}
|
| 226 |
+
bool onTree() const;
|
| 227 |
+
|
| 228 |
+
GCOVBlock &src;
|
| 229 |
+
GCOVBlock &dst;
|
| 230 |
+
uint32_t flags;
|
| 231 |
+
uint64_t count = 0;
|
| 232 |
+
uint64_t cycleCount = 0;
|
| 233 |
+
};
|
| 234 |
+
|
| 235 |
+
/// GCOVFunction - Collects function information.
|
| 236 |
+
class GCOVFunction {
|
| 237 |
+
public:
|
| 238 |
+
using BlockIterator = pointee_iterator<
|
| 239 |
+
SmallVectorImpl<std::unique_ptr<GCOVBlock>>::const_iterator>;
|
| 240 |
+
|
| 241 |
+
GCOVFunction(GCOVFile &file) : file(file) {}
|
| 242 |
+
|
| 243 |
+
StringRef getName(bool demangle) const;
|
| 244 |
+
StringRef getFilename() const;
|
| 245 |
+
uint64_t getEntryCount() const;
|
| 246 |
+
GCOVBlock &getExitBlock() const;
|
| 247 |
+
|
| 248 |
+
iterator_range<BlockIterator> blocksRange() const {
|
| 249 |
+
return make_range(blocks.begin(), blocks.end());
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
void propagateCounts(const GCOVBlock &v, GCOVArc *pred);
|
| 253 |
+
void print(raw_ostream &OS) const;
|
| 254 |
+
void dump() const;
|
| 255 |
+
|
| 256 |
+
GCOVFile &file;
|
| 257 |
+
uint32_t ident = 0;
|
| 258 |
+
uint32_t linenoChecksum;
|
| 259 |
+
uint32_t cfgChecksum = 0;
|
| 260 |
+
uint32_t startLine = 0;
|
| 261 |
+
uint32_t startColumn = 0;
|
| 262 |
+
uint32_t endLine = 0;
|
| 263 |
+
uint32_t endColumn = 0;
|
| 264 |
+
uint8_t artificial = 0;
|
| 265 |
+
StringRef Name;
|
| 266 |
+
mutable SmallString<0> demangled;
|
| 267 |
+
unsigned srcIdx;
|
| 268 |
+
SmallVector<std::unique_ptr<GCOVBlock>, 0> blocks;
|
| 269 |
+
SmallVector<std::unique_ptr<GCOVArc>, 0> arcs, treeArcs;
|
| 270 |
+
DenseSet<const GCOVBlock *> visited;
|
| 271 |
+
};
|
| 272 |
+
|
| 273 |
+
/// GCOVBlock - Collects block information.
|
| 274 |
+
class GCOVBlock {
|
| 275 |
+
public:
|
| 276 |
+
using EdgeIterator = SmallVectorImpl<GCOVArc *>::const_iterator;
|
| 277 |
+
using BlockVector = SmallVector<const GCOVBlock *, 1>;
|
| 278 |
+
using BlockVectorLists = SmallVector<BlockVector, 4>;
|
| 279 |
+
using Edges = SmallVector<GCOVArc *, 4>;
|
| 280 |
+
|
| 281 |
+
GCOVBlock(uint32_t N) : number(N) {}
|
| 282 |
+
|
| 283 |
+
void addLine(uint32_t N) { lines.push_back(N); }
|
| 284 |
+
uint32_t getLastLine() const { return lines.back(); }
|
| 285 |
+
uint64_t getCount() const { return count; }
|
| 286 |
+
|
| 287 |
+
void addSrcEdge(GCOVArc *Edge) { pred.push_back(Edge); }
|
| 288 |
+
|
| 289 |
+
void addDstEdge(GCOVArc *Edge) { succ.push_back(Edge); }
|
| 290 |
+
|
| 291 |
+
iterator_range<EdgeIterator> srcs() const {
|
| 292 |
+
return make_range(pred.begin(), pred.end());
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
iterator_range<EdgeIterator> dsts() const {
|
| 296 |
+
return make_range(succ.begin(), succ.end());
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
void print(raw_ostream &OS) const;
|
| 300 |
+
void dump() const;
|
| 301 |
+
|
| 302 |
+
static uint64_t
|
| 303 |
+
augmentOneCycle(GCOVBlock *src,
|
| 304 |
+
std::vector<std::pair<GCOVBlock *, size_t>> &stack);
|
| 305 |
+
static uint64_t getCyclesCount(const BlockVector &blocks);
|
| 306 |
+
static uint64_t getLineCount(const BlockVector &Blocks);
|
| 307 |
+
|
| 308 |
+
public:
|
| 309 |
+
uint32_t number;
|
| 310 |
+
uint64_t count = 0;
|
| 311 |
+
SmallVector<GCOVArc *, 2> pred;
|
| 312 |
+
SmallVector<GCOVArc *, 2> succ;
|
| 313 |
+
SmallVector<uint32_t, 4> lines;
|
| 314 |
+
bool traversable = false;
|
| 315 |
+
GCOVArc *incoming = nullptr;
|
| 316 |
+
};
|
| 317 |
+
|
| 318 |
+
void gcovOneInput(const GCOV::Options &options, StringRef filename,
|
| 319 |
+
StringRef gcno, StringRef gcda, GCOVFile &file);
|
| 320 |
+
|
| 321 |
+
} // end namespace llvm
|
| 322 |
+
|
| 323 |
+
#endif // LLVM_PROFILEDATA_GCOV_H
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/HashKeyMap.h
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===--- HashKeyMap.h - Wrapper for maps using hash value key ---*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
///
|
| 9 |
+
/// \file
|
| 10 |
+
///
|
| 11 |
+
/// Defines HashKeyMap template.
|
| 12 |
+
///
|
| 13 |
+
//===----------------------------------------------------------------------===//
|
| 14 |
+
|
| 15 |
+
#ifndef LLVM_PROFILEDATA_HASHKEYMAP_H
|
| 16 |
+
#define LLVM_PROFILEDATA_HASHKEYMAP_H
|
| 17 |
+
|
| 18 |
+
#include "llvm/ADT/Hashing.h"
|
| 19 |
+
#include <iterator>
|
| 20 |
+
#include <utility>
|
| 21 |
+
|
| 22 |
+
namespace llvm {
|
| 23 |
+
|
| 24 |
+
namespace sampleprof {
|
| 25 |
+
|
| 26 |
+
/// This class is a wrapper to associative container MapT<KeyT, ValueT> using
|
| 27 |
+
/// the hash value of the original key as the new key. This greatly improves the
|
| 28 |
+
/// performance of insert and query operations especially when hash values of
|
| 29 |
+
/// keys are available a priori, and reduces memory usage if KeyT has a large
|
| 30 |
+
/// size.
|
| 31 |
+
/// All keys with the same hash value are considered equivalent (i.e. hash
|
| 32 |
+
/// collision is silently ignored). Given such feature this class should only be
|
| 33 |
+
/// used where it does not affect compilation correctness, for example, when
|
| 34 |
+
/// loading a sample profile. The original key is not stored, so if the user
|
| 35 |
+
/// needs to preserve it, it should be stored in the mapped type.
|
| 36 |
+
/// Assuming the hashing algorithm is uniform, we use the formula
|
| 37 |
+
/// 1 - Permute(n, k) / n ^ k where n is the universe size and k is number of
|
| 38 |
+
/// elements chosen at random to calculate the probability of collision. With
|
| 39 |
+
/// 1,000,000 entries the probability is negligible:
|
| 40 |
+
/// 1 - (2^64)!/((2^64-1000000)!*(2^64)^1000000) ~= 3*10^-8.
|
| 41 |
+
/// Source: https://en.wikipedia.org/wiki/Birthday_problem
|
| 42 |
+
///
|
| 43 |
+
/// \param MapT The underlying associative container type.
|
| 44 |
+
/// \param KeyT The original key type, which requires the implementation of
|
| 45 |
+
/// llvm::hash_value(KeyT).
|
| 46 |
+
/// \param ValueT The original mapped type, which has the same requirement as
|
| 47 |
+
/// the underlying container.
|
| 48 |
+
/// \param MapTArgs Additional template parameters passed to the underlying
|
| 49 |
+
/// container.
|
| 50 |
+
template <template <typename, typename, typename...> typename MapT,
|
| 51 |
+
typename KeyT, typename ValueT, typename... MapTArgs>
|
| 52 |
+
class HashKeyMap :
|
| 53 |
+
public MapT<decltype(hash_value(KeyT())), ValueT, MapTArgs...> {
|
| 54 |
+
public:
|
| 55 |
+
using base_type = MapT<decltype(hash_value(KeyT())), ValueT, MapTArgs...>;
|
| 56 |
+
using key_type = decltype(hash_value(KeyT()));
|
| 57 |
+
using original_key_type = KeyT;
|
| 58 |
+
using mapped_type = ValueT;
|
| 59 |
+
using value_type = typename base_type::value_type;
|
| 60 |
+
|
| 61 |
+
using iterator = typename base_type::iterator;
|
| 62 |
+
using const_iterator = typename base_type::const_iterator;
|
| 63 |
+
|
| 64 |
+
template <typename... Ts>
|
| 65 |
+
std::pair<iterator, bool> try_emplace(const key_type &Hash,
|
| 66 |
+
const original_key_type &Key,
|
| 67 |
+
Ts &&...Args) {
|
| 68 |
+
assert(Hash == hash_value(Key));
|
| 69 |
+
return base_type::try_emplace(Hash, std::forward<Ts>(Args)...);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
template <typename... Ts>
|
| 73 |
+
std::pair<iterator, bool> try_emplace(const original_key_type &Key,
|
| 74 |
+
Ts &&...Args) {
|
| 75 |
+
return try_emplace(hash_value(Key), Key, std::forward<Ts>(Args)...);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
template <typename... Ts> std::pair<iterator, bool> emplace(Ts &&...Args) {
|
| 79 |
+
return try_emplace(std::forward<Ts>(Args)...);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
mapped_type &operator[](const original_key_type &Key) {
|
| 83 |
+
return try_emplace(Key, mapped_type()).first->second;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
iterator find(const original_key_type &Key) {
|
| 87 |
+
auto It = base_type::find(hash_value(Key));
|
| 88 |
+
if (It != base_type::end())
|
| 89 |
+
return It;
|
| 90 |
+
return base_type::end();
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
const_iterator find(const original_key_type &Key) const {
|
| 94 |
+
auto It = base_type::find(hash_value(Key));
|
| 95 |
+
if (It != base_type::end())
|
| 96 |
+
return It;
|
| 97 |
+
return base_type::end();
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
mapped_type lookup(const original_key_type &Key) const {
|
| 101 |
+
auto It = base_type::find(hash_value(Key));
|
| 102 |
+
if (It != base_type::end())
|
| 103 |
+
return It->second;
|
| 104 |
+
return mapped_type();
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
size_t count(const original_key_type &Key) const {
|
| 108 |
+
return base_type::count(hash_value(Key));
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
size_t erase(const original_key_type &Ctx) {
|
| 112 |
+
auto It = find(Ctx);
|
| 113 |
+
if (It != base_type::end()) {
|
| 114 |
+
base_type::erase(It);
|
| 115 |
+
return 1;
|
| 116 |
+
}
|
| 117 |
+
return 0;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
iterator erase(const_iterator It) {
|
| 121 |
+
return base_type::erase(It);
|
| 122 |
+
}
|
| 123 |
+
};
|
| 124 |
+
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
#endif // LLVM_PROFILEDATA_HASHKEYMAP_H
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/IndexedMemProfData.h
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- IndexedMemProfData.h - MemProf format support ------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file implements IndexedMemProfData, a data structure to hold MemProf
|
| 10 |
+
// in a space optimized format. It also provides utility methods for writing
|
| 11 |
+
// MemProf data.
|
| 12 |
+
//
|
| 13 |
+
//===----------------------------------------------------------------------===//
|
| 14 |
+
|
| 15 |
+
#ifndef LLVM_PROFILEDATA_INDEXEDMEMPROFDATA_H
|
| 16 |
+
#define LLVM_PROFILEDATA_INDEXEDMEMPROFDATA_H
|
| 17 |
+
|
| 18 |
+
#include "llvm/ProfileData/DataAccessProf.h"
|
| 19 |
+
#include "llvm/ProfileData/InstrProf.h"
|
| 20 |
+
#include "llvm/ProfileData/MemProf.h"
|
| 21 |
+
|
| 22 |
+
#include <functional>
|
| 23 |
+
#include <optional>
|
| 24 |
+
|
| 25 |
+
namespace llvm {
|
| 26 |
+
namespace memprof {
|
| 27 |
+
class MemProfSummary;
|
| 28 |
+
struct IndexedMemProfData {
|
| 29 |
+
// A map to hold memprof data per function. The lower 64 bits obtained from
|
| 30 |
+
// the md5 hash of the function name is used to index into the map.
|
| 31 |
+
llvm::MapVector<GlobalValue::GUID, IndexedMemProfRecord> Records;
|
| 32 |
+
|
| 33 |
+
// A map to hold frame id to frame mappings. The mappings are used to
|
| 34 |
+
// convert IndexedMemProfRecord to MemProfRecords with frame information
|
| 35 |
+
// inline.
|
| 36 |
+
llvm::MapVector<FrameId, Frame> Frames;
|
| 37 |
+
|
| 38 |
+
// A map to hold call stack id to call stacks.
|
| 39 |
+
llvm::MapVector<CallStackId, llvm::SmallVector<FrameId>> CallStacks;
|
| 40 |
+
|
| 41 |
+
FrameId addFrame(const Frame &F) {
|
| 42 |
+
const FrameId Id = hashFrame(F);
|
| 43 |
+
Frames.try_emplace(Id, F);
|
| 44 |
+
return Id;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
CallStackId addCallStack(ArrayRef<FrameId> CS) {
|
| 48 |
+
CallStackId CSId = hashCallStack(CS);
|
| 49 |
+
CallStacks.try_emplace(CSId, CS);
|
| 50 |
+
return CSId;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
CallStackId addCallStack(SmallVector<FrameId> &&CS) {
|
| 54 |
+
CallStackId CSId = hashCallStack(CS);
|
| 55 |
+
CallStacks.try_emplace(CSId, std::move(CS));
|
| 56 |
+
return CSId;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
private:
|
| 60 |
+
// Return a hash value based on the contents of the frame. Here we use a
|
| 61 |
+
// cryptographic hash function to minimize the chance of hash collisions. We
|
| 62 |
+
// do persist FrameIds as part of memprof formats up to Version 2, inclusive.
|
| 63 |
+
// However, the deserializer never calls this function; it uses FrameIds
|
| 64 |
+
// merely as keys to look up Frames proper.
|
| 65 |
+
FrameId hashFrame(const Frame &F) const {
|
| 66 |
+
llvm::HashBuilder<llvm::TruncatedBLAKE3<8>, llvm::endianness::little>
|
| 67 |
+
HashBuilder;
|
| 68 |
+
HashBuilder.add(F.Function, F.LineOffset, F.Column, F.IsInlineFrame);
|
| 69 |
+
llvm::BLAKE3Result<8> Hash = HashBuilder.final();
|
| 70 |
+
FrameId Id;
|
| 71 |
+
std::memcpy(&Id, Hash.data(), sizeof(Hash));
|
| 72 |
+
return Id;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
// Compute a CallStackId for a given call stack.
|
| 76 |
+
CallStackId hashCallStack(ArrayRef<FrameId> CS) const {
|
| 77 |
+
llvm::HashBuilder<llvm::TruncatedBLAKE3<8>, llvm::endianness::little>
|
| 78 |
+
HashBuilder;
|
| 79 |
+
for (FrameId F : CS)
|
| 80 |
+
HashBuilder.add(F);
|
| 81 |
+
llvm::BLAKE3Result<8> Hash = HashBuilder.final();
|
| 82 |
+
CallStackId CSId;
|
| 83 |
+
std::memcpy(&CSId, Hash.data(), sizeof(Hash));
|
| 84 |
+
return CSId;
|
| 85 |
+
}
|
| 86 |
+
};
|
| 87 |
+
} // namespace memprof
|
| 88 |
+
|
| 89 |
+
// Write the MemProf data to OS.
|
| 90 |
+
Error writeMemProf(
|
| 91 |
+
ProfOStream &OS, memprof::IndexedMemProfData &MemProfData,
|
| 92 |
+
memprof::IndexedVersion MemProfVersionRequested, bool MemProfFullSchema,
|
| 93 |
+
std::unique_ptr<memprof::DataAccessProfData> DataAccessProfileData,
|
| 94 |
+
std::unique_ptr<memprof::MemProfSummary> MemProfSum);
|
| 95 |
+
} // namespace llvm
|
| 96 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/InstrProf.h
ADDED
|
@@ -0,0 +1,1350 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- InstrProf.h - Instrumented profiling format support ------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// Instrumentation-based profiling data is generated by instrumented
|
| 10 |
+
// binaries through library functions in compiler-rt, and read by the clang
|
| 11 |
+
// frontend to feed PGO.
|
| 12 |
+
//
|
| 13 |
+
//===----------------------------------------------------------------------===//
|
| 14 |
+
|
| 15 |
+
#ifndef LLVM_PROFILEDATA_INSTRPROF_H
|
| 16 |
+
#define LLVM_PROFILEDATA_INSTRPROF_H
|
| 17 |
+
|
| 18 |
+
#include "llvm/ADT/ArrayRef.h"
|
| 19 |
+
#include "llvm/ADT/BitmaskEnum.h"
|
| 20 |
+
#include "llvm/ADT/DenseMap.h"
|
| 21 |
+
#include "llvm/ADT/IntervalMap.h"
|
| 22 |
+
#include "llvm/ADT/STLExtras.h"
|
| 23 |
+
#include "llvm/ADT/StringRef.h"
|
| 24 |
+
#include "llvm/ADT/StringSet.h"
|
| 25 |
+
#include "llvm/IR/GlobalValue.h"
|
| 26 |
+
#include "llvm/IR/ProfileSummary.h"
|
| 27 |
+
#include "llvm/ProfileData/InstrProfData.inc"
|
| 28 |
+
#include "llvm/Support/BalancedPartitioning.h"
|
| 29 |
+
#include "llvm/Support/CommandLine.h"
|
| 30 |
+
#include "llvm/Support/Compiler.h"
|
| 31 |
+
#include "llvm/Support/EndianStream.h"
|
| 32 |
+
#include "llvm/Support/Error.h"
|
| 33 |
+
#include "llvm/Support/ErrorHandling.h"
|
| 34 |
+
#include "llvm/Support/MD5.h"
|
| 35 |
+
#include "llvm/Support/MathExtras.h"
|
| 36 |
+
#include "llvm/Support/raw_ostream.h"
|
| 37 |
+
#include "llvm/TargetParser/Host.h"
|
| 38 |
+
#include "llvm/TargetParser/Triple.h"
|
| 39 |
+
#include <algorithm>
|
| 40 |
+
#include <cassert>
|
| 41 |
+
#include <cstddef>
|
| 42 |
+
#include <cstdint>
|
| 43 |
+
#include <cstring>
|
| 44 |
+
#include <list>
|
| 45 |
+
#include <memory>
|
| 46 |
+
#include <string>
|
| 47 |
+
#include <system_error>
|
| 48 |
+
#include <utility>
|
| 49 |
+
#include <vector>
|
| 50 |
+
|
| 51 |
+
namespace llvm {
|
| 52 |
+
|
| 53 |
+
class Function;
|
| 54 |
+
class GlobalVariable;
|
| 55 |
+
struct InstrProfRecord;
|
| 56 |
+
class InstrProfSymtab;
|
| 57 |
+
class Instruction;
|
| 58 |
+
class MDNode;
|
| 59 |
+
class Module;
|
| 60 |
+
|
| 61 |
+
// A struct to define how the data stream should be patched. For Indexed
|
| 62 |
+
// profiling, only uint64_t data type is needed.
|
| 63 |
+
struct PatchItem {
|
| 64 |
+
uint64_t Pos; // Where to patch.
|
| 65 |
+
ArrayRef<uint64_t> D; // An array of source data.
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
// A wrapper class to abstract writer stream with support of bytes
|
| 69 |
+
// back patching.
|
| 70 |
+
class ProfOStream {
|
| 71 |
+
public:
|
| 72 |
+
ProfOStream(raw_fd_ostream &FD);
|
| 73 |
+
ProfOStream(raw_string_ostream &STR);
|
| 74 |
+
|
| 75 |
+
[[nodiscard]] uint64_t tell() const;
|
| 76 |
+
void write(uint64_t V);
|
| 77 |
+
void write32(uint32_t V);
|
| 78 |
+
void writeByte(uint8_t V);
|
| 79 |
+
|
| 80 |
+
// \c patch can only be called when all data is written and flushed.
|
| 81 |
+
// For raw_string_ostream, the patch is done on the target string
|
| 82 |
+
// directly and it won't be reflected in the stream's internal buffer.
|
| 83 |
+
void patch(ArrayRef<PatchItem> P);
|
| 84 |
+
|
| 85 |
+
// If \c OS is an instance of \c raw_fd_ostream, this field will be
|
| 86 |
+
// true. Otherwise, \c OS will be an raw_string_ostream.
|
| 87 |
+
bool IsFDOStream;
|
| 88 |
+
raw_ostream &OS;
|
| 89 |
+
support::endian::Writer LE;
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
enum InstrProfSectKind {
|
| 93 |
+
#define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) Kind,
|
| 94 |
+
#include "llvm/ProfileData/InstrProfData.inc"
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
/// Return the max count value. We reserver a few large values for special use.
|
| 98 |
+
inline uint64_t getInstrMaxCountValue() {
|
| 99 |
+
return std::numeric_limits<uint64_t>::max() - 2;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/// Return the name of the profile section corresponding to \p IPSK.
|
| 103 |
+
///
|
| 104 |
+
/// The name of the section depends on the object format type \p OF. If
|
| 105 |
+
/// \p AddSegmentInfo is true, a segment prefix and additional linker hints may
|
| 106 |
+
/// be added to the section name (this is the default).
|
| 107 |
+
std::string getInstrProfSectionName(InstrProfSectKind IPSK,
|
| 108 |
+
Triple::ObjectFormatType OF,
|
| 109 |
+
bool AddSegmentInfo = true);
|
| 110 |
+
|
| 111 |
+
/// Return the name profile runtime entry point to do value profiling
|
| 112 |
+
/// for a given site.
|
| 113 |
+
inline StringRef getInstrProfValueProfFuncName() {
|
| 114 |
+
return INSTR_PROF_VALUE_PROF_FUNC_STR;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
/// Return the name profile runtime entry point to do memop size value
|
| 118 |
+
/// profiling.
|
| 119 |
+
inline StringRef getInstrProfValueProfMemOpFuncName() {
|
| 120 |
+
return INSTR_PROF_VALUE_PROF_MEMOP_FUNC_STR;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
/// Return the name prefix of variables containing instrumented function names.
|
| 124 |
+
inline StringRef getInstrProfNameVarPrefix() { return "__profn_"; }
|
| 125 |
+
|
| 126 |
+
/// Return the name prefix of variables containing virtual table profile data.
|
| 127 |
+
inline StringRef getInstrProfVTableVarPrefix() { return "__profvt_"; }
|
| 128 |
+
|
| 129 |
+
/// Return the name prefix of variables containing per-function control data.
|
| 130 |
+
inline StringRef getInstrProfDataVarPrefix() { return "__profd_"; }
|
| 131 |
+
|
| 132 |
+
/// Return the name prefix of profile counter variables.
|
| 133 |
+
inline StringRef getInstrProfCountersVarPrefix() { return "__profc_"; }
|
| 134 |
+
|
| 135 |
+
/// Return the name prefix of profile bitmap variables.
|
| 136 |
+
inline StringRef getInstrProfBitmapVarPrefix() { return "__profbm_"; }
|
| 137 |
+
|
| 138 |
+
/// Return the name prefix of value profile variables.
|
| 139 |
+
inline StringRef getInstrProfValuesVarPrefix() { return "__profvp_"; }
|
| 140 |
+
|
| 141 |
+
/// Return the name of value profile node array variables:
|
| 142 |
+
inline StringRef getInstrProfVNodesVarName() { return "__llvm_prf_vnodes"; }
|
| 143 |
+
|
| 144 |
+
/// Return the name of the variable holding the strings (possibly compressed)
|
| 145 |
+
/// of all function's PGO names.
|
| 146 |
+
inline StringRef getInstrProfNamesVarName() { return "__llvm_prf_nm"; }
|
| 147 |
+
|
| 148 |
+
inline StringRef getInstrProfVTableNamesVarName() { return "__llvm_prf_vnm"; }
|
| 149 |
+
|
| 150 |
+
/// Return the name of a covarage mapping variable (internal linkage)
|
| 151 |
+
/// for each instrumented source module. Such variables are allocated
|
| 152 |
+
/// in the __llvm_covmap section.
|
| 153 |
+
inline StringRef getCoverageMappingVarName() {
|
| 154 |
+
return "__llvm_coverage_mapping";
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/// Return the name of the internal variable recording the array
|
| 158 |
+
/// of PGO name vars referenced by the coverage mapping. The owning
|
| 159 |
+
/// functions of those names are not emitted by FE (e.g, unused inline
|
| 160 |
+
/// functions.)
|
| 161 |
+
inline StringRef getCoverageUnusedNamesVarName() {
|
| 162 |
+
return "__llvm_coverage_names";
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
/// Return the name of function that registers all the per-function control
|
| 166 |
+
/// data at program startup time by calling __llvm_register_function. This
|
| 167 |
+
/// function has internal linkage and is called by __llvm_profile_init
|
| 168 |
+
/// runtime method. This function is not generated for these platforms:
|
| 169 |
+
/// Darwin, Linux, and FreeBSD.
|
| 170 |
+
inline StringRef getInstrProfRegFuncsName() {
|
| 171 |
+
return "__llvm_profile_register_functions";
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
/// Return the name of the runtime interface that registers per-function control
|
| 175 |
+
/// data for one instrumented function.
|
| 176 |
+
inline StringRef getInstrProfRegFuncName() {
|
| 177 |
+
return "__llvm_profile_register_function";
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
/// Return the name of the runtime interface that registers the PGO name
|
| 181 |
+
/// strings.
|
| 182 |
+
inline StringRef getInstrProfNamesRegFuncName() {
|
| 183 |
+
return "__llvm_profile_register_names_function";
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
/// Return the name of the runtime initialization method that is generated by
|
| 187 |
+
/// the compiler. The function calls __llvm_profile_register_functions and
|
| 188 |
+
/// __llvm_profile_override_default_filename functions if needed. This function
|
| 189 |
+
/// has internal linkage and invoked at startup time via init_array.
|
| 190 |
+
inline StringRef getInstrProfInitFuncName() { return "__llvm_profile_init"; }
|
| 191 |
+
|
| 192 |
+
/// Return the name of the hook variable defined in profile runtime library.
|
| 193 |
+
/// A reference to the variable causes the linker to link in the runtime
|
| 194 |
+
/// initialization module (which defines the hook variable).
|
| 195 |
+
inline StringRef getInstrProfRuntimeHookVarName() {
|
| 196 |
+
return INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_RUNTIME_VAR);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
/// Return the name of the compiler generated function that references the
|
| 200 |
+
/// runtime hook variable. The function is a weak global.
|
| 201 |
+
inline StringRef getInstrProfRuntimeHookVarUseFuncName() {
|
| 202 |
+
return "__llvm_profile_runtime_user";
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
inline StringRef getInstrProfCounterBiasVarName() {
|
| 206 |
+
return INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_COUNTER_BIAS_VAR);
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
inline StringRef getInstrProfBitmapBiasVarName() {
|
| 210 |
+
return INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_BITMAP_BIAS_VAR);
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
/// Return the marker used to separate PGO names during serialization.
|
| 214 |
+
inline StringRef getInstrProfNameSeparator() { return "\01"; }
|
| 215 |
+
|
| 216 |
+
/// Determines whether module targets a GPU eligable for PGO
|
| 217 |
+
/// instrumentation
|
| 218 |
+
bool isGPUProfTarget(const Module &M);
|
| 219 |
+
|
| 220 |
+
/// Please use getIRPGOFuncName for LLVM IR instrumentation. This function is
|
| 221 |
+
/// for front-end (Clang, etc) instrumentation.
|
| 222 |
+
/// Return the modified name for function \c F suitable to be
|
| 223 |
+
/// used the key for profile lookup. Variable \c InLTO indicates if this
|
| 224 |
+
/// is called in LTO optimization passes.
|
| 225 |
+
std::string getPGOFuncName(const Function &F, bool InLTO = false,
|
| 226 |
+
uint64_t Version = INSTR_PROF_INDEX_VERSION);
|
| 227 |
+
|
| 228 |
+
/// Return the modified name for a function suitable to be
|
| 229 |
+
/// used the key for profile lookup. The function's original
|
| 230 |
+
/// name is \c RawFuncName and has linkage of type \c Linkage.
|
| 231 |
+
/// The function is defined in module \c FileName.
|
| 232 |
+
std::string getPGOFuncName(StringRef RawFuncName,
|
| 233 |
+
GlobalValue::LinkageTypes Linkage,
|
| 234 |
+
StringRef FileName,
|
| 235 |
+
uint64_t Version = INSTR_PROF_INDEX_VERSION);
|
| 236 |
+
|
| 237 |
+
/// \return the modified name for function \c F suitable to be
|
| 238 |
+
/// used as the key for IRPGO profile lookup. \c InLTO indicates if this is
|
| 239 |
+
/// called from LTO optimization passes.
|
| 240 |
+
std::string getIRPGOFuncName(const Function &F, bool InLTO = false);
|
| 241 |
+
|
| 242 |
+
/// \return the filename and the function name parsed from the output of
|
| 243 |
+
/// \c getIRPGOFuncName()
|
| 244 |
+
std::pair<StringRef, StringRef> getParsedIRPGOName(StringRef IRPGOName);
|
| 245 |
+
|
| 246 |
+
/// Return the name of the global variable used to store a function
|
| 247 |
+
/// name in PGO instrumentation. \c FuncName is the IRPGO function name
|
| 248 |
+
/// (returned by \c getIRPGOFuncName) for LLVM IR instrumentation and PGO
|
| 249 |
+
/// function name (returned by \c getPGOFuncName) for front-end instrumentation.
|
| 250 |
+
std::string getPGOFuncNameVarName(StringRef FuncName,
|
| 251 |
+
GlobalValue::LinkageTypes Linkage);
|
| 252 |
+
|
| 253 |
+
/// Create and return the global variable for function name used in PGO
|
| 254 |
+
/// instrumentation. \c FuncName is the IRPGO function name (returned by
|
| 255 |
+
/// \c getIRPGOFuncName) for LLVM IR instrumentation and PGO function name
|
| 256 |
+
/// (returned by \c getPGOFuncName) for front-end instrumentation.
|
| 257 |
+
GlobalVariable *createPGOFuncNameVar(Function &F, StringRef PGOFuncName);
|
| 258 |
+
|
| 259 |
+
/// Create and return the global variable for function name used in PGO
|
| 260 |
+
/// instrumentation. \c FuncName is the IRPGO function name (returned by
|
| 261 |
+
/// \c getIRPGOFuncName) for LLVM IR instrumentation and PGO function name
|
| 262 |
+
/// (returned by \c getPGOFuncName) for front-end instrumentation.
|
| 263 |
+
GlobalVariable *createPGOFuncNameVar(Module &M,
|
| 264 |
+
GlobalValue::LinkageTypes Linkage,
|
| 265 |
+
StringRef PGOFuncName);
|
| 266 |
+
|
| 267 |
+
/// Return the initializer in string of the PGO name var \c NameVar.
|
| 268 |
+
StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar);
|
| 269 |
+
|
| 270 |
+
/// Given a PGO function name, remove the filename prefix and return
|
| 271 |
+
/// the original (static) function name.
|
| 272 |
+
StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName,
|
| 273 |
+
StringRef FileName = "<unknown>");
|
| 274 |
+
|
| 275 |
+
/// Given a vector of strings (names of global objects like functions or,
|
| 276 |
+
/// virtual tables) \c NameStrs, the method generates a combined string \c
|
| 277 |
+
/// Result that is ready to be serialized. The \c Result string is comprised of
|
| 278 |
+
/// three fields: The first field is the length of the uncompressed strings, and
|
| 279 |
+
/// the the second field is the length of the zlib-compressed string. Both
|
| 280 |
+
/// fields are encoded in ULEB128. If \c doCompress is false, the
|
| 281 |
+
/// third field is the uncompressed strings; otherwise it is the
|
| 282 |
+
/// compressed string. When the string compression is off, the
|
| 283 |
+
/// second field will have value zero.
|
| 284 |
+
Error collectGlobalObjectNameStrings(ArrayRef<std::string> NameStrs,
|
| 285 |
+
bool doCompression, std::string &Result);
|
| 286 |
+
|
| 287 |
+
/// Produce \c Result string with the same format described above. The input
|
| 288 |
+
/// is vector of PGO function name variables that are referenced.
|
| 289 |
+
/// The global variable element in 'NameVars' is a string containing the pgo
|
| 290 |
+
/// name of a function. See `createPGOFuncNameVar` that creates these global
|
| 291 |
+
/// variables.
|
| 292 |
+
Error collectPGOFuncNameStrings(ArrayRef<GlobalVariable *> NameVars,
|
| 293 |
+
std::string &Result, bool doCompression = true);
|
| 294 |
+
|
| 295 |
+
Error collectVTableStrings(ArrayRef<GlobalVariable *> VTables,
|
| 296 |
+
std::string &Result, bool doCompression);
|
| 297 |
+
|
| 298 |
+
/// Check if INSTR_PROF_RAW_VERSION_VAR is defined. This global is only being
|
| 299 |
+
/// set in IR PGO compilation.
|
| 300 |
+
bool isIRPGOFlagSet(const Module *M);
|
| 301 |
+
|
| 302 |
+
/// Check if we can safely rename this Comdat function. Instances of the same
|
| 303 |
+
/// comdat function may have different control flows thus can not share the
|
| 304 |
+
/// same counter variable.
|
| 305 |
+
bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken = false);
|
| 306 |
+
|
| 307 |
+
enum InstrProfValueKind : uint32_t {
|
| 308 |
+
#define VALUE_PROF_KIND(Enumerator, Value, Descr) Enumerator = Value,
|
| 309 |
+
#include "llvm/ProfileData/InstrProfData.inc"
|
| 310 |
+
};
|
| 311 |
+
|
| 312 |
+
/// Get the value profile data for value site \p SiteIdx from \p InstrProfR
|
| 313 |
+
/// and annotate the instruction \p Inst with the value profile meta data.
|
| 314 |
+
/// Annotate up to \p MaxMDCount (default 3) number of records per value site.
|
| 315 |
+
void annotateValueSite(Module &M, Instruction &Inst,
|
| 316 |
+
const InstrProfRecord &InstrProfR,
|
| 317 |
+
InstrProfValueKind ValueKind, uint32_t SiteIndx,
|
| 318 |
+
uint32_t MaxMDCount = 3);
|
| 319 |
+
|
| 320 |
+
/// Same as the above interface but using an ArrayRef, as well as \p Sum.
|
| 321 |
+
/// This function will not annotate !prof metadata on the instruction if the
|
| 322 |
+
/// referenced array is empty.
|
| 323 |
+
void annotateValueSite(Module &M, Instruction &Inst,
|
| 324 |
+
ArrayRef<InstrProfValueData> VDs, uint64_t Sum,
|
| 325 |
+
InstrProfValueKind ValueKind, uint32_t MaxMDCount);
|
| 326 |
+
|
| 327 |
+
// TODO: Unify metadata name 'PGOFuncName' and 'PGOName', by supporting read
|
| 328 |
+
// of this metadata for backward compatibility and generating 'PGOName' only.
|
| 329 |
+
/// Extract the value profile data from \p Inst and returns them if \p Inst is
|
| 330 |
+
/// annotated with value profile data. Returns an empty vector otherwise.
|
| 331 |
+
SmallVector<InstrProfValueData, 4>
|
| 332 |
+
getValueProfDataFromInst(const Instruction &Inst, InstrProfValueKind ValueKind,
|
| 333 |
+
uint32_t MaxNumValueData, uint64_t &TotalC,
|
| 334 |
+
bool GetNoICPValue = false);
|
| 335 |
+
|
| 336 |
+
inline StringRef getPGOFuncNameMetadataName() { return "PGOFuncName"; }
|
| 337 |
+
|
| 338 |
+
inline StringRef getPGONameMetadataName() { return "PGOName"; }
|
| 339 |
+
|
| 340 |
+
/// Return the PGOFuncName meta data associated with a function.
|
| 341 |
+
MDNode *getPGOFuncNameMetadata(const Function &F);
|
| 342 |
+
|
| 343 |
+
std::string getPGOName(const GlobalVariable &V, bool InLTO = false);
|
| 344 |
+
|
| 345 |
+
/// Create the PGOFuncName meta data if PGOFuncName is different from
|
| 346 |
+
/// function's raw name. This should only apply to internal linkage functions
|
| 347 |
+
/// declared by users only.
|
| 348 |
+
/// TODO: Update all callers to 'createPGONameMetadata' and deprecate this
|
| 349 |
+
/// function.
|
| 350 |
+
void createPGOFuncNameMetadata(Function &F, StringRef PGOFuncName);
|
| 351 |
+
|
| 352 |
+
/// Create the PGOName metadata if a global object's PGO name is different from
|
| 353 |
+
/// its mangled name. This should apply to local-linkage global objects only.
|
| 354 |
+
void createPGONameMetadata(GlobalObject &GO, StringRef PGOName);
|
| 355 |
+
|
| 356 |
+
/// Check if we can use Comdat for profile variables. This will eliminate
|
| 357 |
+
/// the duplicated profile variables for Comdat functions.
|
| 358 |
+
bool needsComdatForCounter(const GlobalObject &GV, const Module &M);
|
| 359 |
+
|
| 360 |
+
/// \c NameStrings is a string composed of one or more possibly encoded
|
| 361 |
+
/// sub-strings. The substrings are separated by `\01` (returned by
|
| 362 |
+
/// InstrProf.h:getInstrProfNameSeparator). This method decodes the string and
|
| 363 |
+
/// calls `NameCallback` for each substring.
|
| 364 |
+
Error readAndDecodeStrings(StringRef NameStrings,
|
| 365 |
+
std::function<Error(StringRef)> NameCallback);
|
| 366 |
+
|
| 367 |
+
/// An enum describing the attributes of an instrumented profile.
|
| 368 |
+
enum class InstrProfKind {
|
| 369 |
+
Unknown = 0x0,
|
| 370 |
+
// A frontend clang profile, incompatible with other attrs.
|
| 371 |
+
FrontendInstrumentation = 0x1,
|
| 372 |
+
// An IR-level profile (default when -fprofile-generate is used).
|
| 373 |
+
IRInstrumentation = 0x2,
|
| 374 |
+
// A profile with entry basic block instrumentation.
|
| 375 |
+
FunctionEntryInstrumentation = 0x4,
|
| 376 |
+
// A context sensitive IR-level profile.
|
| 377 |
+
ContextSensitive = 0x8,
|
| 378 |
+
// Use single byte probes for coverage.
|
| 379 |
+
SingleByteCoverage = 0x10,
|
| 380 |
+
// Only instrument the function entry basic block.
|
| 381 |
+
FunctionEntryOnly = 0x20,
|
| 382 |
+
// A memory profile collected using -fprofile=memory.
|
| 383 |
+
MemProf = 0x40,
|
| 384 |
+
// A temporal profile.
|
| 385 |
+
TemporalProfile = 0x80,
|
| 386 |
+
// A profile with loop entry basic blocks instrumentation.
|
| 387 |
+
LoopEntriesInstrumentation = 0x100,
|
| 388 |
+
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/LoopEntriesInstrumentation)
|
| 389 |
+
};
|
| 390 |
+
|
| 391 |
+
const std::error_category &instrprof_category();
|
| 392 |
+
|
| 393 |
+
enum class instrprof_error {
|
| 394 |
+
success = 0,
|
| 395 |
+
eof,
|
| 396 |
+
unrecognized_format,
|
| 397 |
+
bad_magic,
|
| 398 |
+
bad_header,
|
| 399 |
+
unsupported_version,
|
| 400 |
+
unsupported_hash_type,
|
| 401 |
+
too_large,
|
| 402 |
+
truncated,
|
| 403 |
+
malformed,
|
| 404 |
+
missing_correlation_info,
|
| 405 |
+
unexpected_correlation_info,
|
| 406 |
+
unable_to_correlate_profile,
|
| 407 |
+
unknown_function,
|
| 408 |
+
invalid_prof,
|
| 409 |
+
hash_mismatch,
|
| 410 |
+
count_mismatch,
|
| 411 |
+
bitmap_mismatch,
|
| 412 |
+
counter_overflow,
|
| 413 |
+
value_site_count_mismatch,
|
| 414 |
+
compress_failed,
|
| 415 |
+
uncompress_failed,
|
| 416 |
+
empty_raw_profile,
|
| 417 |
+
zlib_unavailable,
|
| 418 |
+
raw_profile_version_mismatch,
|
| 419 |
+
counter_value_too_large,
|
| 420 |
+
};
|
| 421 |
+
|
| 422 |
+
/// An ordered list of functions identified by their NameRef found in
|
| 423 |
+
/// INSTR_PROF_DATA
|
| 424 |
+
struct TemporalProfTraceTy {
|
| 425 |
+
std::vector<uint64_t> FunctionNameRefs;
|
| 426 |
+
uint64_t Weight;
|
| 427 |
+
TemporalProfTraceTy(std::initializer_list<uint64_t> Trace = {},
|
| 428 |
+
uint64_t Weight = 1)
|
| 429 |
+
: FunctionNameRefs(Trace), Weight(Weight) {}
|
| 430 |
+
|
| 431 |
+
/// Use a set of temporal profile traces to create a list of balanced
|
| 432 |
+
/// partitioning function nodes used by BalancedPartitioning to generate a
|
| 433 |
+
/// function order that reduces page faults during startup
|
| 434 |
+
static void createBPFunctionNodes(ArrayRef<TemporalProfTraceTy> Traces,
|
| 435 |
+
std::vector<BPFunctionNode> &Nodes,
|
| 436 |
+
bool RemoveOutlierUNs = true);
|
| 437 |
+
};
|
| 438 |
+
|
| 439 |
+
inline std::error_code make_error_code(instrprof_error E) {
|
| 440 |
+
return std::error_code(static_cast<int>(E), instrprof_category());
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
class InstrProfError : public ErrorInfo<InstrProfError> {
|
| 444 |
+
public:
|
| 445 |
+
InstrProfError(instrprof_error Err, const Twine &ErrStr = Twine())
|
| 446 |
+
: Err(Err), Msg(ErrStr.str()) {
|
| 447 |
+
assert(Err != instrprof_error::success && "Not an error");
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
std::string message() const override;
|
| 451 |
+
|
| 452 |
+
void log(raw_ostream &OS) const override { OS << message(); }
|
| 453 |
+
|
| 454 |
+
std::error_code convertToErrorCode() const override {
|
| 455 |
+
return make_error_code(Err);
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
instrprof_error get() const { return Err; }
|
| 459 |
+
const std::string &getMessage() const { return Msg; }
|
| 460 |
+
|
| 461 |
+
/// Consume an Error and return the raw enum value contained within it, and
|
| 462 |
+
/// the optional error message. The Error must either be a success value, or
|
| 463 |
+
/// contain a single InstrProfError.
|
| 464 |
+
static std::pair<instrprof_error, std::string> take(Error E) {
|
| 465 |
+
auto Err = instrprof_error::success;
|
| 466 |
+
std::string Msg = "";
|
| 467 |
+
handleAllErrors(std::move(E), [&Err, &Msg](const InstrProfError &IPE) {
|
| 468 |
+
assert(Err == instrprof_error::success && "Multiple errors encountered");
|
| 469 |
+
Err = IPE.get();
|
| 470 |
+
Msg = IPE.getMessage();
|
| 471 |
+
});
|
| 472 |
+
return {Err, Msg};
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
static char ID;
|
| 476 |
+
|
| 477 |
+
private:
|
| 478 |
+
instrprof_error Err;
|
| 479 |
+
std::string Msg;
|
| 480 |
+
};
|
| 481 |
+
|
| 482 |
+
namespace object {
|
| 483 |
+
|
| 484 |
+
class SectionRef;
|
| 485 |
+
|
| 486 |
+
} // end namespace object
|
| 487 |
+
|
| 488 |
+
namespace IndexedInstrProf {
|
| 489 |
+
|
| 490 |
+
uint64_t ComputeHash(StringRef K);
|
| 491 |
+
|
| 492 |
+
} // end namespace IndexedInstrProf
|
| 493 |
+
|
| 494 |
+
/// A symbol table used for function [IR]PGO name look-up with keys
|
| 495 |
+
/// (such as pointers, md5hash values) to the function. A function's
|
| 496 |
+
/// [IR]PGO name or name's md5hash are used in retrieving the profile
|
| 497 |
+
/// data of the function. See \c getIRPGOFuncName() and \c getPGOFuncName
|
| 498 |
+
/// methods for details how [IR]PGO name is formed.
|
| 499 |
+
class InstrProfSymtab {
|
| 500 |
+
public:
|
| 501 |
+
using AddrHashMap = std::vector<std::pair<uint64_t, uint64_t>>;
|
| 502 |
+
|
| 503 |
+
// Returns the canonical name of the given PGOName. In a canonical name, all
|
| 504 |
+
// suffixes that begins with "." except ".__uniq." are stripped.
|
| 505 |
+
// FIXME: Unify this with `FunctionSamples::getCanonicalFnName`.
|
| 506 |
+
static StringRef getCanonicalName(StringRef PGOName);
|
| 507 |
+
|
| 508 |
+
private:
|
| 509 |
+
using AddrIntervalMap =
|
| 510 |
+
IntervalMap<uint64_t, uint64_t, 4, IntervalMapHalfOpenInfo<uint64_t>>;
|
| 511 |
+
StringRef Data;
|
| 512 |
+
uint64_t Address = 0;
|
| 513 |
+
// Unique name strings. Used to ensure entries in MD5NameMap (a vector that's
|
| 514 |
+
// going to be sorted) has unique MD5 keys in the first place.
|
| 515 |
+
StringSet<> NameTab;
|
| 516 |
+
// Records the unique virtual table names. This is used by InstrProfWriter to
|
| 517 |
+
// write out an on-disk chained hash table of virtual table names.
|
| 518 |
+
// InstrProfWriter stores per function profile data (keyed by function names)
|
| 519 |
+
// so it doesn't use a StringSet for function names.
|
| 520 |
+
StringSet<> VTableNames;
|
| 521 |
+
// A map from MD5 keys to function name strings.
|
| 522 |
+
std::vector<std::pair<uint64_t, StringRef>> MD5NameMap;
|
| 523 |
+
// A map from MD5 keys to function define. We only populate this map
|
| 524 |
+
// when build the Symtab from a Module.
|
| 525 |
+
std::vector<std::pair<uint64_t, Function *>> MD5FuncMap;
|
| 526 |
+
// A map from MD5 to the global variable. This map is only populated when
|
| 527 |
+
// building the symtab from a module. Use separate container instances for
|
| 528 |
+
// `MD5FuncMap` and `MD5VTableMap`.
|
| 529 |
+
// TODO: Unify the container type and the lambda function 'mapName' inside
|
| 530 |
+
// add{Func,VTable}WithName.
|
| 531 |
+
DenseMap<uint64_t, GlobalVariable *> MD5VTableMap;
|
| 532 |
+
// A map from function runtime address to function name MD5 hash.
|
| 533 |
+
// This map is only populated and used by raw instr profile reader.
|
| 534 |
+
AddrHashMap AddrToMD5Map;
|
| 535 |
+
|
| 536 |
+
AddrIntervalMap::Allocator VTableAddrMapAllocator;
|
| 537 |
+
// This map is only populated and used by raw instr profile reader.
|
| 538 |
+
AddrIntervalMap VTableAddrMap;
|
| 539 |
+
bool Sorted = false;
|
| 540 |
+
|
| 541 |
+
static StringRef getExternalSymbol() { return "** External Symbol **"; }
|
| 542 |
+
|
| 543 |
+
// Add the function into the symbol table, by creating the following
|
| 544 |
+
// map entries:
|
| 545 |
+
// name-set = {PGOFuncName} union {getCanonicalName(PGOFuncName)}
|
| 546 |
+
// - In MD5NameMap: <MD5Hash(name), name> for name in name-set
|
| 547 |
+
// - In MD5FuncMap: <MD5Hash(name), &F> for name in name-set
|
| 548 |
+
// The canonical name is only added if \c AddCanonical is true.
|
| 549 |
+
Error addFuncWithName(Function &F, StringRef PGOFuncName, bool AddCanonical);
|
| 550 |
+
|
| 551 |
+
// Add the vtable into the symbol table, by creating the following
|
| 552 |
+
// map entries:
|
| 553 |
+
// name-set = {PGOName} union {getCanonicalName(PGOName)}
|
| 554 |
+
// - In MD5NameMap: <MD5Hash(name), name> for name in name-set
|
| 555 |
+
// - In MD5VTableMap: <MD5Hash(name), name> for name in name-set
|
| 556 |
+
Error addVTableWithName(GlobalVariable &V, StringRef PGOVTableName);
|
| 557 |
+
|
| 558 |
+
// If the symtab is created by a series of calls to \c addFuncName, \c
|
| 559 |
+
// finalizeSymtab needs to be called before looking up function names.
|
| 560 |
+
// This is required because the underlying map is a vector (for space
|
| 561 |
+
// efficiency) which needs to be sorted.
|
| 562 |
+
inline void finalizeSymtab();
|
| 563 |
+
|
| 564 |
+
public:
|
| 565 |
+
InstrProfSymtab() : VTableAddrMap(VTableAddrMapAllocator) {}
|
| 566 |
+
|
| 567 |
+
// Not copyable or movable.
|
| 568 |
+
// Consider std::unique_ptr for move.
|
| 569 |
+
InstrProfSymtab(const InstrProfSymtab &) = delete;
|
| 570 |
+
InstrProfSymtab &operator=(const InstrProfSymtab &) = delete;
|
| 571 |
+
InstrProfSymtab(InstrProfSymtab &&) = delete;
|
| 572 |
+
InstrProfSymtab &operator=(InstrProfSymtab &&) = delete;
|
| 573 |
+
|
| 574 |
+
/// Create InstrProfSymtab from an object file section which
|
| 575 |
+
/// contains function PGO names. When section may contain raw
|
| 576 |
+
/// string data or string data in compressed form. This method
|
| 577 |
+
/// only initialize the symtab with reference to the data and
|
| 578 |
+
/// the section base address. The decompression will be delayed
|
| 579 |
+
/// until before it is used. See also \c create(StringRef) method.
|
| 580 |
+
Error create(object::SectionRef &Section);
|
| 581 |
+
|
| 582 |
+
/// \c NameStrings is a string composed of one of more sub-strings
|
| 583 |
+
/// encoded in the format described in \c collectPGOFuncNameStrings.
|
| 584 |
+
/// This method is a wrapper to \c readAndDecodeStrings method.
|
| 585 |
+
Error create(StringRef NameStrings);
|
| 586 |
+
|
| 587 |
+
/// Initialize symtab states with function names and vtable names. \c
|
| 588 |
+
/// FuncNameStrings is a string composed of one or more encoded function name
|
| 589 |
+
/// strings, and \c VTableNameStrings composes of one or more encoded vtable
|
| 590 |
+
/// names. This interface is solely used by raw profile reader.
|
| 591 |
+
Error create(StringRef FuncNameStrings, StringRef VTableNameStrings);
|
| 592 |
+
|
| 593 |
+
/// Initialize 'this' with the set of vtable names encoded in
|
| 594 |
+
/// \c CompressedVTableNames.
|
| 595 |
+
Error initVTableNamesFromCompressedStrings(StringRef CompressedVTableNames);
|
| 596 |
+
|
| 597 |
+
/// This interface is used by reader of CoverageMapping test
|
| 598 |
+
/// format.
|
| 599 |
+
inline Error create(StringRef D, uint64_t BaseAddr);
|
| 600 |
+
|
| 601 |
+
/// A wrapper interface to populate the PGO symtab with functions
|
| 602 |
+
/// decls from module \c M. This interface is used by transformation
|
| 603 |
+
/// passes such as indirect function call promotion. Variable \c InLTO
|
| 604 |
+
/// indicates if this is called from LTO optimization passes.
|
| 605 |
+
/// A canonical name, removing non-__uniq suffixes, is added if
|
| 606 |
+
/// \c AddCanonical is true.
|
| 607 |
+
Error create(Module &M, bool InLTO = false, bool AddCanonical = true);
|
| 608 |
+
|
| 609 |
+
/// Create InstrProfSymtab from a set of names iteratable from
|
| 610 |
+
/// \p IterRange. This interface is used by IndexedProfReader.
|
| 611 |
+
template <typename NameIterRange>
|
| 612 |
+
Error create(const NameIterRange &IterRange);
|
| 613 |
+
|
| 614 |
+
/// Create InstrProfSymtab from a set of function names and vtable
|
| 615 |
+
/// names iteratable from \p IterRange. This interface is used by
|
| 616 |
+
/// IndexedProfReader.
|
| 617 |
+
template <typename FuncNameIterRange, typename VTableNameIterRange>
|
| 618 |
+
Error create(const FuncNameIterRange &FuncIterRange,
|
| 619 |
+
const VTableNameIterRange &VTableIterRange);
|
| 620 |
+
|
| 621 |
+
// Map the MD5 of the symbol name to the name.
|
| 622 |
+
Error addSymbolName(StringRef SymbolName) {
|
| 623 |
+
if (SymbolName.empty())
|
| 624 |
+
return make_error<InstrProfError>(instrprof_error::malformed,
|
| 625 |
+
"symbol name is empty");
|
| 626 |
+
|
| 627 |
+
// Insert into NameTab so that MD5NameMap (a vector that will be sorted)
|
| 628 |
+
// won't have duplicated entries in the first place.
|
| 629 |
+
auto Ins = NameTab.insert(SymbolName);
|
| 630 |
+
if (Ins.second) {
|
| 631 |
+
MD5NameMap.push_back(std::make_pair(
|
| 632 |
+
IndexedInstrProf::ComputeHash(SymbolName), Ins.first->getKey()));
|
| 633 |
+
Sorted = false;
|
| 634 |
+
}
|
| 635 |
+
return Error::success();
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
/// The method name is kept since there are many callers.
|
| 639 |
+
/// It just forwards to 'addSymbolName'.
|
| 640 |
+
Error addFuncName(StringRef FuncName) { return addSymbolName(FuncName); }
|
| 641 |
+
|
| 642 |
+
/// Adds VTableName as a known symbol, and inserts it to a map that
|
| 643 |
+
/// tracks all vtable names.
|
| 644 |
+
Error addVTableName(StringRef VTableName) {
|
| 645 |
+
if (Error E = addSymbolName(VTableName))
|
| 646 |
+
return E;
|
| 647 |
+
|
| 648 |
+
// Record VTableName. InstrProfWriter uses this set. The comment around
|
| 649 |
+
// class member explains why.
|
| 650 |
+
VTableNames.insert(VTableName);
|
| 651 |
+
return Error::success();
|
| 652 |
+
}
|
| 653 |
+
|
| 654 |
+
const StringSet<> &getVTableNames() const { return VTableNames; }
|
| 655 |
+
|
| 656 |
+
/// Map a function address to its name's MD5 hash. This interface
|
| 657 |
+
/// is only used by the raw profiler reader.
|
| 658 |
+
void mapAddress(uint64_t Addr, uint64_t MD5Val) {
|
| 659 |
+
AddrToMD5Map.push_back(std::make_pair(Addr, MD5Val));
|
| 660 |
+
}
|
| 661 |
+
|
| 662 |
+
/// Map the address range (i.e., [start_address, end_address)) of a variable
|
| 663 |
+
/// to its names' MD5 hash. This interface is only used by the raw profile
|
| 664 |
+
/// reader.
|
| 665 |
+
void mapVTableAddress(uint64_t StartAddr, uint64_t EndAddr, uint64_t MD5Val) {
|
| 666 |
+
VTableAddrMap.insert(StartAddr, EndAddr, MD5Val);
|
| 667 |
+
}
|
| 668 |
+
|
| 669 |
+
/// Return a function's hash, or 0, if the function isn't in this SymTab.
|
| 670 |
+
uint64_t getFunctionHashFromAddress(uint64_t Address);
|
| 671 |
+
|
| 672 |
+
/// Return a vtable's hash, or 0 if the vtable doesn't exist in this SymTab.
|
| 673 |
+
uint64_t getVTableHashFromAddress(uint64_t Address);
|
| 674 |
+
|
| 675 |
+
/// Return function's PGO name from the function name's symbol
|
| 676 |
+
/// address in the object file. If an error occurs, return
|
| 677 |
+
/// an empty string.
|
| 678 |
+
StringRef getFuncName(uint64_t FuncNameAddress, size_t NameSize);
|
| 679 |
+
|
| 680 |
+
/// Return name of functions or global variables from the name's md5 hash
|
| 681 |
+
/// value. If not found, return an empty string.
|
| 682 |
+
inline StringRef getFuncOrVarName(uint64_t ValMD5Hash);
|
| 683 |
+
|
| 684 |
+
/// Just like getFuncOrVarName, except that it will return literal string
|
| 685 |
+
/// 'External Symbol' if the function or global variable is external to
|
| 686 |
+
/// this symbol table.
|
| 687 |
+
inline StringRef getFuncOrVarNameIfDefined(uint64_t ValMD5Hash);
|
| 688 |
+
|
| 689 |
+
/// True if Symbol is the value used to represent external symbols.
|
| 690 |
+
static bool isExternalSymbol(const StringRef &Symbol) {
|
| 691 |
+
return Symbol == InstrProfSymtab::getExternalSymbol();
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
/// Return function from the name's md5 hash. Return nullptr if not found.
|
| 695 |
+
inline Function *getFunction(uint64_t FuncMD5Hash);
|
| 696 |
+
|
| 697 |
+
/// Return the global variable corresponding to md5 hash. Return nullptr if
|
| 698 |
+
/// not found.
|
| 699 |
+
inline GlobalVariable *getGlobalVariable(uint64_t MD5Hash);
|
| 700 |
+
|
| 701 |
+
/// Return the name section data.
|
| 702 |
+
inline StringRef getNameData() const { return Data; }
|
| 703 |
+
|
| 704 |
+
/// Dump the symbols in this table.
|
| 705 |
+
void dumpNames(raw_ostream &OS) const;
|
| 706 |
+
};
|
| 707 |
+
|
| 708 |
+
Error InstrProfSymtab::create(StringRef D, uint64_t BaseAddr) {
|
| 709 |
+
Data = D;
|
| 710 |
+
Address = BaseAddr;
|
| 711 |
+
return Error::success();
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
template <typename NameIterRange>
|
| 715 |
+
Error InstrProfSymtab::create(const NameIterRange &IterRange) {
|
| 716 |
+
for (auto Name : IterRange)
|
| 717 |
+
if (Error E = addFuncName(Name))
|
| 718 |
+
return E;
|
| 719 |
+
|
| 720 |
+
finalizeSymtab();
|
| 721 |
+
return Error::success();
|
| 722 |
+
}
|
| 723 |
+
|
| 724 |
+
template <typename FuncNameIterRange, typename VTableNameIterRange>
|
| 725 |
+
Error InstrProfSymtab::create(const FuncNameIterRange &FuncIterRange,
|
| 726 |
+
const VTableNameIterRange &VTableIterRange) {
|
| 727 |
+
// Iterate elements by StringRef rather than by const reference.
|
| 728 |
+
// StringRef is small enough, so the loop is efficient whether
|
| 729 |
+
// element in the range is std::string or StringRef.
|
| 730 |
+
for (StringRef Name : FuncIterRange)
|
| 731 |
+
if (Error E = addFuncName(Name))
|
| 732 |
+
return E;
|
| 733 |
+
|
| 734 |
+
for (StringRef VTableName : VTableIterRange)
|
| 735 |
+
if (Error E = addVTableName(VTableName))
|
| 736 |
+
return E;
|
| 737 |
+
|
| 738 |
+
finalizeSymtab();
|
| 739 |
+
return Error::success();
|
| 740 |
+
}
|
| 741 |
+
|
| 742 |
+
void InstrProfSymtab::finalizeSymtab() {
|
| 743 |
+
if (Sorted)
|
| 744 |
+
return;
|
| 745 |
+
llvm::sort(MD5NameMap, less_first());
|
| 746 |
+
llvm::sort(MD5FuncMap, less_first());
|
| 747 |
+
llvm::sort(AddrToMD5Map, less_first());
|
| 748 |
+
AddrToMD5Map.erase(llvm::unique(AddrToMD5Map), AddrToMD5Map.end());
|
| 749 |
+
Sorted = true;
|
| 750 |
+
}
|
| 751 |
+
|
| 752 |
+
StringRef InstrProfSymtab::getFuncOrVarNameIfDefined(uint64_t MD5Hash) {
|
| 753 |
+
StringRef ret = getFuncOrVarName(MD5Hash);
|
| 754 |
+
if (ret.empty())
|
| 755 |
+
return InstrProfSymtab::getExternalSymbol();
|
| 756 |
+
return ret;
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
StringRef InstrProfSymtab::getFuncOrVarName(uint64_t MD5Hash) {
|
| 760 |
+
finalizeSymtab();
|
| 761 |
+
auto Result = llvm::lower_bound(MD5NameMap, MD5Hash,
|
| 762 |
+
[](const std::pair<uint64_t, StringRef> &LHS,
|
| 763 |
+
uint64_t RHS) { return LHS.first < RHS; });
|
| 764 |
+
if (Result != MD5NameMap.end() && Result->first == MD5Hash)
|
| 765 |
+
return Result->second;
|
| 766 |
+
return StringRef();
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
Function* InstrProfSymtab::getFunction(uint64_t FuncMD5Hash) {
|
| 770 |
+
finalizeSymtab();
|
| 771 |
+
auto Result = llvm::lower_bound(MD5FuncMap, FuncMD5Hash,
|
| 772 |
+
[](const std::pair<uint64_t, Function *> &LHS,
|
| 773 |
+
uint64_t RHS) { return LHS.first < RHS; });
|
| 774 |
+
if (Result != MD5FuncMap.end() && Result->first == FuncMD5Hash)
|
| 775 |
+
return Result->second;
|
| 776 |
+
return nullptr;
|
| 777 |
+
}
|
| 778 |
+
|
| 779 |
+
GlobalVariable *InstrProfSymtab::getGlobalVariable(uint64_t MD5Hash) {
|
| 780 |
+
return MD5VTableMap.lookup(MD5Hash);
|
| 781 |
+
}
|
| 782 |
+
|
| 783 |
+
// To store the sums of profile count values, or the percentage of
|
| 784 |
+
// the sums of the total count values.
|
| 785 |
+
struct CountSumOrPercent {
|
| 786 |
+
uint64_t NumEntries = 0;
|
| 787 |
+
double CountSum = 0.0f;
|
| 788 |
+
std::array<double, IPVK_Last - IPVK_First + 1> ValueCounts = {};
|
| 789 |
+
CountSumOrPercent() = default;
|
| 790 |
+
void reset() {
|
| 791 |
+
NumEntries = 0;
|
| 792 |
+
CountSum = 0.0f;
|
| 793 |
+
ValueCounts.fill(0.0f);
|
| 794 |
+
}
|
| 795 |
+
};
|
| 796 |
+
|
| 797 |
+
// Function level or program level overlap information.
|
| 798 |
+
struct OverlapStats {
|
| 799 |
+
enum OverlapStatsLevel { ProgramLevel, FunctionLevel };
|
| 800 |
+
// Sum of the total count values for the base profile.
|
| 801 |
+
CountSumOrPercent Base;
|
| 802 |
+
// Sum of the total count values for the test profile.
|
| 803 |
+
CountSumOrPercent Test;
|
| 804 |
+
// Overlap lap score. Should be in range of [0.0f to 1.0f].
|
| 805 |
+
CountSumOrPercent Overlap;
|
| 806 |
+
CountSumOrPercent Mismatch;
|
| 807 |
+
CountSumOrPercent Unique;
|
| 808 |
+
OverlapStatsLevel Level;
|
| 809 |
+
const std::string *BaseFilename = nullptr;
|
| 810 |
+
const std::string *TestFilename = nullptr;
|
| 811 |
+
StringRef FuncName;
|
| 812 |
+
uint64_t FuncHash = 0;
|
| 813 |
+
bool Valid = false;
|
| 814 |
+
|
| 815 |
+
OverlapStats(OverlapStatsLevel L = ProgramLevel) : Level(L) {}
|
| 816 |
+
|
| 817 |
+
void dump(raw_fd_ostream &OS) const;
|
| 818 |
+
|
| 819 |
+
void setFuncInfo(StringRef Name, uint64_t Hash) {
|
| 820 |
+
FuncName = Name;
|
| 821 |
+
FuncHash = Hash;
|
| 822 |
+
}
|
| 823 |
+
|
| 824 |
+
Error accumulateCounts(const std::string &BaseFilename,
|
| 825 |
+
const std::string &TestFilename, bool IsCS);
|
| 826 |
+
void addOneMismatch(const CountSumOrPercent &MismatchFunc);
|
| 827 |
+
void addOneUnique(const CountSumOrPercent &UniqueFunc);
|
| 828 |
+
|
| 829 |
+
static inline double score(uint64_t Val1, uint64_t Val2, double Sum1,
|
| 830 |
+
double Sum2) {
|
| 831 |
+
if (Sum1 < 1.0f || Sum2 < 1.0f)
|
| 832 |
+
return 0.0f;
|
| 833 |
+
return std::min(Val1 / Sum1, Val2 / Sum2);
|
| 834 |
+
}
|
| 835 |
+
};
|
| 836 |
+
|
| 837 |
+
// This is used to filter the functions whose overlap information
|
| 838 |
+
// to be output.
|
| 839 |
+
struct OverlapFuncFilters {
|
| 840 |
+
uint64_t ValueCutoff;
|
| 841 |
+
const std::string NameFilter;
|
| 842 |
+
};
|
| 843 |
+
|
| 844 |
+
struct InstrProfValueSiteRecord {
|
| 845 |
+
/// Value profiling data pairs at a given value site.
|
| 846 |
+
std::vector<InstrProfValueData> ValueData;
|
| 847 |
+
|
| 848 |
+
InstrProfValueSiteRecord() = default;
|
| 849 |
+
InstrProfValueSiteRecord(std::vector<InstrProfValueData> &&VD)
|
| 850 |
+
: ValueData(VD) {}
|
| 851 |
+
|
| 852 |
+
/// Sort ValueData ascending by Value
|
| 853 |
+
void sortByTargetValues() {
|
| 854 |
+
llvm::sort(ValueData,
|
| 855 |
+
[](const InstrProfValueData &L, const InstrProfValueData &R) {
|
| 856 |
+
return L.Value < R.Value;
|
| 857 |
+
});
|
| 858 |
+
}
|
| 859 |
+
/// Sort ValueData Descending by Count
|
| 860 |
+
inline void sortByCount();
|
| 861 |
+
|
| 862 |
+
/// Merge data from another InstrProfValueSiteRecord
|
| 863 |
+
/// Optionally scale merged counts by \p Weight.
|
| 864 |
+
void merge(InstrProfValueSiteRecord &Input, uint64_t Weight,
|
| 865 |
+
function_ref<void(instrprof_error)> Warn);
|
| 866 |
+
/// Scale up value profile data counts by N (Numerator) / D (Denominator).
|
| 867 |
+
void scale(uint64_t N, uint64_t D, function_ref<void(instrprof_error)> Warn);
|
| 868 |
+
|
| 869 |
+
/// Compute the overlap b/w this record and Input record.
|
| 870 |
+
void overlap(InstrProfValueSiteRecord &Input, uint32_t ValueKind,
|
| 871 |
+
OverlapStats &Overlap, OverlapStats &FuncLevelOverlap);
|
| 872 |
+
};
|
| 873 |
+
|
| 874 |
+
/// Profiling information for a single function.
|
| 875 |
+
struct InstrProfRecord {
|
| 876 |
+
std::vector<uint64_t> Counts;
|
| 877 |
+
std::vector<uint8_t> BitmapBytes;
|
| 878 |
+
|
| 879 |
+
InstrProfRecord() = default;
|
| 880 |
+
InstrProfRecord(std::vector<uint64_t> Counts) : Counts(std::move(Counts)) {}
|
| 881 |
+
InstrProfRecord(std::vector<uint64_t> Counts,
|
| 882 |
+
std::vector<uint8_t> BitmapBytes)
|
| 883 |
+
: Counts(std::move(Counts)), BitmapBytes(std::move(BitmapBytes)) {}
|
| 884 |
+
InstrProfRecord(InstrProfRecord &&) = default;
|
| 885 |
+
InstrProfRecord(const InstrProfRecord &RHS)
|
| 886 |
+
: Counts(RHS.Counts), BitmapBytes(RHS.BitmapBytes),
|
| 887 |
+
ValueData(RHS.ValueData
|
| 888 |
+
? std::make_unique<ValueProfData>(*RHS.ValueData)
|
| 889 |
+
: nullptr) {}
|
| 890 |
+
InstrProfRecord &operator=(InstrProfRecord &&) = default;
|
| 891 |
+
InstrProfRecord &operator=(const InstrProfRecord &RHS) {
|
| 892 |
+
Counts = RHS.Counts;
|
| 893 |
+
BitmapBytes = RHS.BitmapBytes;
|
| 894 |
+
if (!RHS.ValueData) {
|
| 895 |
+
ValueData = nullptr;
|
| 896 |
+
return *this;
|
| 897 |
+
}
|
| 898 |
+
if (!ValueData)
|
| 899 |
+
ValueData = std::make_unique<ValueProfData>(*RHS.ValueData);
|
| 900 |
+
else
|
| 901 |
+
*ValueData = *RHS.ValueData;
|
| 902 |
+
return *this;
|
| 903 |
+
}
|
| 904 |
+
|
| 905 |
+
/// Return the number of value profile kinds with non-zero number
|
| 906 |
+
/// of profile sites.
|
| 907 |
+
inline uint32_t getNumValueKinds() const;
|
| 908 |
+
/// Return the number of instrumented sites for ValueKind.
|
| 909 |
+
inline uint32_t getNumValueSites(uint32_t ValueKind) const;
|
| 910 |
+
|
| 911 |
+
/// Return the total number of ValueData for ValueKind.
|
| 912 |
+
inline uint32_t getNumValueData(uint32_t ValueKind) const;
|
| 913 |
+
|
| 914 |
+
/// Return the array of profiled values at \p Site.
|
| 915 |
+
inline ArrayRef<InstrProfValueData> getValueArrayForSite(uint32_t ValueKind,
|
| 916 |
+
uint32_t Site) const;
|
| 917 |
+
|
| 918 |
+
/// Reserve space for NumValueSites sites.
|
| 919 |
+
inline void reserveSites(uint32_t ValueKind, uint32_t NumValueSites);
|
| 920 |
+
|
| 921 |
+
/// Add ValueData for ValueKind at value Site. We do not support adding sites
|
| 922 |
+
/// out of order. Site must go up from 0 one by one.
|
| 923 |
+
void addValueData(uint32_t ValueKind, uint32_t Site,
|
| 924 |
+
ArrayRef<InstrProfValueData> VData,
|
| 925 |
+
InstrProfSymtab *SymTab);
|
| 926 |
+
|
| 927 |
+
/// Merge the counts in \p Other into this one.
|
| 928 |
+
/// Optionally scale merged counts by \p Weight.
|
| 929 |
+
void merge(InstrProfRecord &Other, uint64_t Weight,
|
| 930 |
+
function_ref<void(instrprof_error)> Warn);
|
| 931 |
+
|
| 932 |
+
/// Scale up profile counts (including value profile data) by
|
| 933 |
+
/// a factor of (N / D).
|
| 934 |
+
void scale(uint64_t N, uint64_t D, function_ref<void(instrprof_error)> Warn);
|
| 935 |
+
|
| 936 |
+
/// Sort value profile data (per site) by count.
|
| 937 |
+
void sortValueData() {
|
| 938 |
+
for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
|
| 939 |
+
for (auto &SR : getValueSitesForKind(Kind))
|
| 940 |
+
SR.sortByCount();
|
| 941 |
+
}
|
| 942 |
+
|
| 943 |
+
/// Clear value data entries and edge counters.
|
| 944 |
+
void Clear() {
|
| 945 |
+
Counts.clear();
|
| 946 |
+
clearValueData();
|
| 947 |
+
}
|
| 948 |
+
|
| 949 |
+
/// Clear value data entries
|
| 950 |
+
void clearValueData() { ValueData = nullptr; }
|
| 951 |
+
|
| 952 |
+
/// Compute the sums of all counts and store in Sum.
|
| 953 |
+
void accumulateCounts(CountSumOrPercent &Sum) const;
|
| 954 |
+
|
| 955 |
+
/// Compute the overlap b/w this IntrprofRecord and Other.
|
| 956 |
+
void overlap(InstrProfRecord &Other, OverlapStats &Overlap,
|
| 957 |
+
OverlapStats &FuncLevelOverlap, uint64_t ValueCutoff);
|
| 958 |
+
|
| 959 |
+
/// Compute the overlap of value profile counts.
|
| 960 |
+
void overlapValueProfData(uint32_t ValueKind, InstrProfRecord &Src,
|
| 961 |
+
OverlapStats &Overlap,
|
| 962 |
+
OverlapStats &FuncLevelOverlap);
|
| 963 |
+
|
| 964 |
+
enum CountPseudoKind {
|
| 965 |
+
NotPseudo = 0,
|
| 966 |
+
PseudoHot,
|
| 967 |
+
PseudoWarm,
|
| 968 |
+
};
|
| 969 |
+
enum PseudoCountVal {
|
| 970 |
+
HotFunctionVal = -1,
|
| 971 |
+
WarmFunctionVal = -2,
|
| 972 |
+
};
|
| 973 |
+
CountPseudoKind getCountPseudoKind() const {
|
| 974 |
+
uint64_t FirstCount = Counts[0];
|
| 975 |
+
if (FirstCount == (uint64_t)HotFunctionVal)
|
| 976 |
+
return PseudoHot;
|
| 977 |
+
if (FirstCount == (uint64_t)WarmFunctionVal)
|
| 978 |
+
return PseudoWarm;
|
| 979 |
+
return NotPseudo;
|
| 980 |
+
}
|
| 981 |
+
void setPseudoCount(CountPseudoKind Kind) {
|
| 982 |
+
if (Kind == PseudoHot)
|
| 983 |
+
Counts[0] = (uint64_t)HotFunctionVal;
|
| 984 |
+
else if (Kind == PseudoWarm)
|
| 985 |
+
Counts[0] = (uint64_t)WarmFunctionVal;
|
| 986 |
+
}
|
| 987 |
+
|
| 988 |
+
private:
|
| 989 |
+
using ValueProfData = std::array<std::vector<InstrProfValueSiteRecord>,
|
| 990 |
+
IPVK_Last - IPVK_First + 1>;
|
| 991 |
+
std::unique_ptr<ValueProfData> ValueData;
|
| 992 |
+
|
| 993 |
+
MutableArrayRef<InstrProfValueSiteRecord>
|
| 994 |
+
getValueSitesForKind(uint32_t ValueKind) {
|
| 995 |
+
// Cast to /add/ const (should be an implicit_cast, ideally, if that's ever
|
| 996 |
+
// implemented in LLVM) to call the const overload of this function, then
|
| 997 |
+
// cast away the constness from the result.
|
| 998 |
+
auto AR = const_cast<const InstrProfRecord *>(this)->getValueSitesForKind(
|
| 999 |
+
ValueKind);
|
| 1000 |
+
return MutableArrayRef(
|
| 1001 |
+
const_cast<InstrProfValueSiteRecord *>(AR.data()), AR.size());
|
| 1002 |
+
}
|
| 1003 |
+
ArrayRef<InstrProfValueSiteRecord>
|
| 1004 |
+
getValueSitesForKind(uint32_t ValueKind) const {
|
| 1005 |
+
if (!ValueData)
|
| 1006 |
+
return {};
|
| 1007 |
+
assert(IPVK_First <= ValueKind && ValueKind <= IPVK_Last &&
|
| 1008 |
+
"Unknown value kind!");
|
| 1009 |
+
return (*ValueData)[ValueKind - IPVK_First];
|
| 1010 |
+
}
|
| 1011 |
+
|
| 1012 |
+
std::vector<InstrProfValueSiteRecord> &
|
| 1013 |
+
getOrCreateValueSitesForKind(uint32_t ValueKind) {
|
| 1014 |
+
if (!ValueData)
|
| 1015 |
+
ValueData = std::make_unique<ValueProfData>();
|
| 1016 |
+
assert(IPVK_First <= ValueKind && ValueKind <= IPVK_Last &&
|
| 1017 |
+
"Unknown value kind!");
|
| 1018 |
+
return (*ValueData)[ValueKind - IPVK_First];
|
| 1019 |
+
}
|
| 1020 |
+
|
| 1021 |
+
// Map indirect call target name hash to name string.
|
| 1022 |
+
uint64_t remapValue(uint64_t Value, uint32_t ValueKind,
|
| 1023 |
+
InstrProfSymtab *SymTab);
|
| 1024 |
+
|
| 1025 |
+
// Merge Value Profile data from Src record to this record for ValueKind.
|
| 1026 |
+
// Scale merged value counts by \p Weight.
|
| 1027 |
+
void mergeValueProfData(uint32_t ValkeKind, InstrProfRecord &Src,
|
| 1028 |
+
uint64_t Weight,
|
| 1029 |
+
function_ref<void(instrprof_error)> Warn);
|
| 1030 |
+
|
| 1031 |
+
// Scale up value profile data count by N (Numerator) / D (Denominator).
|
| 1032 |
+
void scaleValueProfData(uint32_t ValueKind, uint64_t N, uint64_t D,
|
| 1033 |
+
function_ref<void(instrprof_error)> Warn);
|
| 1034 |
+
};
|
| 1035 |
+
|
| 1036 |
+
struct NamedInstrProfRecord : InstrProfRecord {
|
| 1037 |
+
StringRef Name;
|
| 1038 |
+
uint64_t Hash;
|
| 1039 |
+
|
| 1040 |
+
// We reserve this bit as the flag for context sensitive profile record.
|
| 1041 |
+
static const int CS_FLAG_IN_FUNC_HASH = 60;
|
| 1042 |
+
|
| 1043 |
+
NamedInstrProfRecord() = default;
|
| 1044 |
+
NamedInstrProfRecord(StringRef Name, uint64_t Hash,
|
| 1045 |
+
std::vector<uint64_t> Counts)
|
| 1046 |
+
: InstrProfRecord(std::move(Counts)), Name(Name), Hash(Hash) {}
|
| 1047 |
+
NamedInstrProfRecord(StringRef Name, uint64_t Hash,
|
| 1048 |
+
std::vector<uint64_t> Counts,
|
| 1049 |
+
std::vector<uint8_t> BitmapBytes)
|
| 1050 |
+
: InstrProfRecord(std::move(Counts), std::move(BitmapBytes)), Name(Name),
|
| 1051 |
+
Hash(Hash) {}
|
| 1052 |
+
|
| 1053 |
+
static bool hasCSFlagInHash(uint64_t FuncHash) {
|
| 1054 |
+
return ((FuncHash >> CS_FLAG_IN_FUNC_HASH) & 1);
|
| 1055 |
+
}
|
| 1056 |
+
static void setCSFlagInHash(uint64_t &FuncHash) {
|
| 1057 |
+
FuncHash |= ((uint64_t)1 << CS_FLAG_IN_FUNC_HASH);
|
| 1058 |
+
}
|
| 1059 |
+
};
|
| 1060 |
+
|
| 1061 |
+
uint32_t InstrProfRecord::getNumValueKinds() const {
|
| 1062 |
+
uint32_t NumValueKinds = 0;
|
| 1063 |
+
for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
|
| 1064 |
+
NumValueKinds += !(getValueSitesForKind(Kind).empty());
|
| 1065 |
+
return NumValueKinds;
|
| 1066 |
+
}
|
| 1067 |
+
|
| 1068 |
+
uint32_t InstrProfRecord::getNumValueData(uint32_t ValueKind) const {
|
| 1069 |
+
uint32_t N = 0;
|
| 1070 |
+
for (const auto &SR : getValueSitesForKind(ValueKind))
|
| 1071 |
+
N += SR.ValueData.size();
|
| 1072 |
+
return N;
|
| 1073 |
+
}
|
| 1074 |
+
|
| 1075 |
+
uint32_t InstrProfRecord::getNumValueSites(uint32_t ValueKind) const {
|
| 1076 |
+
return getValueSitesForKind(ValueKind).size();
|
| 1077 |
+
}
|
| 1078 |
+
|
| 1079 |
+
ArrayRef<InstrProfValueData>
|
| 1080 |
+
InstrProfRecord::getValueArrayForSite(uint32_t ValueKind, uint32_t Site) const {
|
| 1081 |
+
return getValueSitesForKind(ValueKind)[Site].ValueData;
|
| 1082 |
+
}
|
| 1083 |
+
|
| 1084 |
+
void InstrProfRecord::reserveSites(uint32_t ValueKind, uint32_t NumValueSites) {
|
| 1085 |
+
if (!NumValueSites)
|
| 1086 |
+
return;
|
| 1087 |
+
getOrCreateValueSitesForKind(ValueKind).reserve(NumValueSites);
|
| 1088 |
+
}
|
| 1089 |
+
|
| 1090 |
+
// Include definitions for value profile data
|
| 1091 |
+
#define INSTR_PROF_VALUE_PROF_DATA
|
| 1092 |
+
#include "llvm/ProfileData/InstrProfData.inc"
|
| 1093 |
+
|
| 1094 |
+
void InstrProfValueSiteRecord::sortByCount() {
|
| 1095 |
+
llvm::stable_sort(
|
| 1096 |
+
ValueData, [](const InstrProfValueData &L, const InstrProfValueData &R) {
|
| 1097 |
+
return L.Count > R.Count;
|
| 1098 |
+
});
|
| 1099 |
+
// Now truncate
|
| 1100 |
+
size_t max_s = INSTR_PROF_MAX_NUM_VAL_PER_SITE;
|
| 1101 |
+
if (ValueData.size() > max_s)
|
| 1102 |
+
ValueData.resize(max_s);
|
| 1103 |
+
}
|
| 1104 |
+
|
| 1105 |
+
namespace IndexedInstrProf {
|
| 1106 |
+
|
| 1107 |
+
enum class HashT : uint32_t {
|
| 1108 |
+
MD5,
|
| 1109 |
+
Last = MD5
|
| 1110 |
+
};
|
| 1111 |
+
|
| 1112 |
+
inline uint64_t ComputeHash(HashT Type, StringRef K) {
|
| 1113 |
+
switch (Type) {
|
| 1114 |
+
case HashT::MD5:
|
| 1115 |
+
return MD5Hash(K);
|
| 1116 |
+
}
|
| 1117 |
+
llvm_unreachable("Unhandled hash type");
|
| 1118 |
+
}
|
| 1119 |
+
|
| 1120 |
+
const uint64_t Magic = 0x8169666f72706cff; // "\xfflprofi\x81"
|
| 1121 |
+
|
| 1122 |
+
enum ProfVersion {
|
| 1123 |
+
// Version 1 is the first version. In this version, the value of
|
| 1124 |
+
// a key/value pair can only include profile data of a single function.
|
| 1125 |
+
// Due to this restriction, the number of block counters for a given
|
| 1126 |
+
// function is not recorded but derived from the length of the value.
|
| 1127 |
+
Version1 = 1,
|
| 1128 |
+
// The version 2 format supports recording profile data of multiple
|
| 1129 |
+
// functions which share the same key in one value field. To support this,
|
| 1130 |
+
// the number block counters is recorded as an uint64_t field right after the
|
| 1131 |
+
// function structural hash.
|
| 1132 |
+
Version2 = 2,
|
| 1133 |
+
// Version 3 supports value profile data. The value profile data is expected
|
| 1134 |
+
// to follow the block counter profile data.
|
| 1135 |
+
Version3 = 3,
|
| 1136 |
+
// In this version, profile summary data \c IndexedInstrProf::Summary is
|
| 1137 |
+
// stored after the profile header.
|
| 1138 |
+
Version4 = 4,
|
| 1139 |
+
// In this version, the frontend PGO stable hash algorithm defaults to V2.
|
| 1140 |
+
Version5 = 5,
|
| 1141 |
+
// In this version, the frontend PGO stable hash algorithm got fixed and
|
| 1142 |
+
// may produce hashes different from Version5.
|
| 1143 |
+
Version6 = 6,
|
| 1144 |
+
// An additional counter is added around logical operators.
|
| 1145 |
+
Version7 = 7,
|
| 1146 |
+
// An additional (optional) memory profile type is added.
|
| 1147 |
+
Version8 = 8,
|
| 1148 |
+
// Binary ids are added.
|
| 1149 |
+
Version9 = 9,
|
| 1150 |
+
// An additional (optional) temporal profile traces section is added.
|
| 1151 |
+
Version10 = 10,
|
| 1152 |
+
// An additional field is used for bitmap bytes.
|
| 1153 |
+
Version11 = 11,
|
| 1154 |
+
// VTable profiling, decision record and bitmap are modified for mcdc.
|
| 1155 |
+
Version12 = 12,
|
| 1156 |
+
// The current version is 12.
|
| 1157 |
+
CurrentVersion = INSTR_PROF_INDEX_VERSION
|
| 1158 |
+
};
|
| 1159 |
+
const uint64_t Version = ProfVersion::CurrentVersion;
|
| 1160 |
+
|
| 1161 |
+
const HashT HashType = HashT::MD5;
|
| 1162 |
+
|
| 1163 |
+
inline uint64_t ComputeHash(StringRef K) { return ComputeHash(HashType, K); }
|
| 1164 |
+
|
| 1165 |
+
// This structure defines the file header of the LLVM profile
|
| 1166 |
+
// data file in indexed-format. Please update llvm/docs/InstrProfileFormat.rst
|
| 1167 |
+
// as appropriate when updating the indexed profile format.
|
| 1168 |
+
struct Header {
|
| 1169 |
+
uint64_t Magic = IndexedInstrProf::Magic;
|
| 1170 |
+
// The lower 32 bits specify the version of the indexed profile.
|
| 1171 |
+
// The most significant 32 bits are reserved to specify the variant types of
|
| 1172 |
+
// the profile.
|
| 1173 |
+
uint64_t Version = 0;
|
| 1174 |
+
uint64_t Unused = 0; // Becomes unused since version 4
|
| 1175 |
+
uint64_t HashType = static_cast<uint64_t>(IndexedInstrProf::HashType);
|
| 1176 |
+
// This field records the offset of this hash table's metadata (i.e., the
|
| 1177 |
+
// number of buckets and entries), which follows right after the payload of
|
| 1178 |
+
// the entire hash table.
|
| 1179 |
+
uint64_t HashOffset = 0;
|
| 1180 |
+
uint64_t MemProfOffset = 0;
|
| 1181 |
+
uint64_t BinaryIdOffset = 0;
|
| 1182 |
+
uint64_t TemporalProfTracesOffset = 0;
|
| 1183 |
+
uint64_t VTableNamesOffset = 0;
|
| 1184 |
+
// New fields should only be added at the end to ensure that the size
|
| 1185 |
+
// computation is correct. The methods below need to be updated to ensure that
|
| 1186 |
+
// the new field is read correctly.
|
| 1187 |
+
|
| 1188 |
+
// Reads a header struct from the buffer. Header fields are in machine native
|
| 1189 |
+
// endianness.
|
| 1190 |
+
static Expected<Header> readFromBuffer(const unsigned char *Buffer);
|
| 1191 |
+
|
| 1192 |
+
// Returns the size of the header in bytes for all valid fields based on the
|
| 1193 |
+
// version. I.e a older version header will return a smaller size.
|
| 1194 |
+
size_t size() const;
|
| 1195 |
+
|
| 1196 |
+
// Return the indexed profile version, i.e., the least significant 32 bits
|
| 1197 |
+
// in Header.Version.
|
| 1198 |
+
uint64_t getIndexedProfileVersion() const;
|
| 1199 |
+
};
|
| 1200 |
+
|
| 1201 |
+
// Profile summary data recorded in the profile data file in indexed
|
| 1202 |
+
// format. It is introduced in version 4. The summary data follows
|
| 1203 |
+
// right after the profile file header.
|
| 1204 |
+
struct Summary {
|
| 1205 |
+
struct Entry {
|
| 1206 |
+
uint64_t Cutoff; ///< The required percentile of total execution count.
|
| 1207 |
+
uint64_t
|
| 1208 |
+
MinBlockCount; ///< The minimum execution count for this percentile.
|
| 1209 |
+
uint64_t NumBlocks; ///< Number of blocks >= the minumum execution count.
|
| 1210 |
+
};
|
| 1211 |
+
// The field kind enumerator to assigned value mapping should remain
|
| 1212 |
+
// unchanged when a new kind is added or an old kind gets deleted in
|
| 1213 |
+
// the future.
|
| 1214 |
+
enum SummaryFieldKind {
|
| 1215 |
+
/// The total number of functions instrumented.
|
| 1216 |
+
TotalNumFunctions = 0,
|
| 1217 |
+
/// Total number of instrumented blocks/edges.
|
| 1218 |
+
TotalNumBlocks = 1,
|
| 1219 |
+
/// The maximal execution count among all functions.
|
| 1220 |
+
/// This field does not exist for profile data from IR based
|
| 1221 |
+
/// instrumentation.
|
| 1222 |
+
MaxFunctionCount = 2,
|
| 1223 |
+
/// Max block count of the program.
|
| 1224 |
+
MaxBlockCount = 3,
|
| 1225 |
+
/// Max internal block count of the program (excluding entry blocks).
|
| 1226 |
+
MaxInternalBlockCount = 4,
|
| 1227 |
+
/// The sum of all instrumented block counts.
|
| 1228 |
+
TotalBlockCount = 5,
|
| 1229 |
+
NumKinds = TotalBlockCount + 1
|
| 1230 |
+
};
|
| 1231 |
+
|
| 1232 |
+
// The number of summmary fields following the summary header.
|
| 1233 |
+
uint64_t NumSummaryFields;
|
| 1234 |
+
// The number of Cutoff Entries (Summary::Entry) following summary fields.
|
| 1235 |
+
uint64_t NumCutoffEntries;
|
| 1236 |
+
|
| 1237 |
+
Summary() = delete;
|
| 1238 |
+
Summary(uint32_t Size) { memset(this, 0, Size); }
|
| 1239 |
+
|
| 1240 |
+
void operator delete(void *ptr) { ::operator delete(ptr); }
|
| 1241 |
+
|
| 1242 |
+
static uint32_t getSize(uint32_t NumSumFields, uint32_t NumCutoffEntries) {
|
| 1243 |
+
return sizeof(Summary) + NumCutoffEntries * sizeof(Entry) +
|
| 1244 |
+
NumSumFields * sizeof(uint64_t);
|
| 1245 |
+
}
|
| 1246 |
+
|
| 1247 |
+
const uint64_t *getSummaryDataBase() const {
|
| 1248 |
+
return reinterpret_cast<const uint64_t *>(this + 1);
|
| 1249 |
+
}
|
| 1250 |
+
|
| 1251 |
+
uint64_t *getSummaryDataBase() {
|
| 1252 |
+
return reinterpret_cast<uint64_t *>(this + 1);
|
| 1253 |
+
}
|
| 1254 |
+
|
| 1255 |
+
const Entry *getCutoffEntryBase() const {
|
| 1256 |
+
return reinterpret_cast<const Entry *>(
|
| 1257 |
+
&getSummaryDataBase()[NumSummaryFields]);
|
| 1258 |
+
}
|
| 1259 |
+
|
| 1260 |
+
Entry *getCutoffEntryBase() {
|
| 1261 |
+
return reinterpret_cast<Entry *>(&getSummaryDataBase()[NumSummaryFields]);
|
| 1262 |
+
}
|
| 1263 |
+
|
| 1264 |
+
uint64_t get(SummaryFieldKind K) const {
|
| 1265 |
+
return getSummaryDataBase()[K];
|
| 1266 |
+
}
|
| 1267 |
+
|
| 1268 |
+
void set(SummaryFieldKind K, uint64_t V) {
|
| 1269 |
+
getSummaryDataBase()[K] = V;
|
| 1270 |
+
}
|
| 1271 |
+
|
| 1272 |
+
const Entry &getEntry(uint32_t I) const { return getCutoffEntryBase()[I]; }
|
| 1273 |
+
|
| 1274 |
+
void setEntry(uint32_t I, const ProfileSummaryEntry &E) {
|
| 1275 |
+
Entry &ER = getCutoffEntryBase()[I];
|
| 1276 |
+
ER.Cutoff = E.Cutoff;
|
| 1277 |
+
ER.MinBlockCount = E.MinCount;
|
| 1278 |
+
ER.NumBlocks = E.NumCounts;
|
| 1279 |
+
}
|
| 1280 |
+
};
|
| 1281 |
+
|
| 1282 |
+
inline std::unique_ptr<Summary> allocSummary(uint32_t TotalSize) {
|
| 1283 |
+
return std::unique_ptr<Summary>(new (::operator new(TotalSize))
|
| 1284 |
+
Summary(TotalSize));
|
| 1285 |
+
}
|
| 1286 |
+
|
| 1287 |
+
} // end namespace IndexedInstrProf
|
| 1288 |
+
|
| 1289 |
+
namespace RawInstrProf {
|
| 1290 |
+
|
| 1291 |
+
// Version 1: First version
|
| 1292 |
+
// Version 2: Added value profile data section. Per-function control data
|
| 1293 |
+
// struct has more fields to describe value profile information.
|
| 1294 |
+
// Version 3: Compressed name section support. Function PGO name reference
|
| 1295 |
+
// from control data struct is changed from raw pointer to Name's MD5 value.
|
| 1296 |
+
// Version 4: ValueDataBegin and ValueDataSizes fields are removed from the
|
| 1297 |
+
// raw header.
|
| 1298 |
+
// Version 5: Bit 60 of FuncHash is reserved for the flag for the context
|
| 1299 |
+
// sensitive records.
|
| 1300 |
+
// Version 6: Added binary id.
|
| 1301 |
+
// Version 7: Reorder binary id and include version in signature.
|
| 1302 |
+
// Version 8: Use relative counter pointer.
|
| 1303 |
+
// Version 9: Added relative bitmap bytes pointer and count used by MC/DC.
|
| 1304 |
+
// Version 10: Added vtable, a new type of value profile data.
|
| 1305 |
+
const uint64_t Version = INSTR_PROF_RAW_VERSION;
|
| 1306 |
+
|
| 1307 |
+
template <class IntPtrT> inline uint64_t getMagic();
|
| 1308 |
+
template <> inline uint64_t getMagic<uint64_t>() {
|
| 1309 |
+
return INSTR_PROF_RAW_MAGIC_64;
|
| 1310 |
+
}
|
| 1311 |
+
|
| 1312 |
+
template <> inline uint64_t getMagic<uint32_t>() {
|
| 1313 |
+
return INSTR_PROF_RAW_MAGIC_32;
|
| 1314 |
+
}
|
| 1315 |
+
|
| 1316 |
+
// Per-function profile data header/control structure.
|
| 1317 |
+
// The definition should match the structure defined in
|
| 1318 |
+
// compiler-rt/lib/profile/InstrProfiling.h.
|
| 1319 |
+
// It should also match the synthesized type in
|
| 1320 |
+
// Transforms/Instrumentation/InstrProfiling.cpp:getOrCreateRegionCounters.
|
| 1321 |
+
template <class IntPtrT> struct alignas(8) ProfileData {
|
| 1322 |
+
#define INSTR_PROF_DATA(Type, LLVMType, Name, Init) Type Name;
|
| 1323 |
+
#include "llvm/ProfileData/InstrProfData.inc"
|
| 1324 |
+
};
|
| 1325 |
+
|
| 1326 |
+
template <class IntPtrT> struct alignas(8) VTableProfileData {
|
| 1327 |
+
#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Init) Type Name;
|
| 1328 |
+
#include "llvm/ProfileData/InstrProfData.inc"
|
| 1329 |
+
};
|
| 1330 |
+
|
| 1331 |
+
// File header structure of the LLVM profile data in raw format.
|
| 1332 |
+
// The definition should match the header referenced in
|
| 1333 |
+
// compiler-rt/lib/profile/InstrProfilingFile.c and
|
| 1334 |
+
// InstrProfilingBuffer.c.
|
| 1335 |
+
struct Header {
|
| 1336 |
+
#define INSTR_PROF_RAW_HEADER(Type, Name, Init) const Type Name;
|
| 1337 |
+
#include "llvm/ProfileData/InstrProfData.inc"
|
| 1338 |
+
};
|
| 1339 |
+
|
| 1340 |
+
} // end namespace RawInstrProf
|
| 1341 |
+
|
| 1342 |
+
// Create the variable for the profile file name.
|
| 1343 |
+
void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput);
|
| 1344 |
+
|
| 1345 |
+
// Whether to compress function names in profile records, and filenames in
|
| 1346 |
+
// code coverage mappings. Used by the Instrumentation library and unit tests.
|
| 1347 |
+
extern cl::opt<bool> DoInstrProfNameCompression;
|
| 1348 |
+
|
| 1349 |
+
} // end namespace llvm
|
| 1350 |
+
#endif // LLVM_PROFILEDATA_INSTRPROF_H
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/InstrProfCorrelator.h
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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//===- InstrProfCorrelator.h ------------------------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
// This file defines InstrProfCorrelator used to generate PGO/coverage profiles
|
| 9 |
+
// from raw profile data and debug info/binary file.
|
| 10 |
+
//===----------------------------------------------------------------------===//
|
| 11 |
+
|
| 12 |
+
#ifndef LLVM_PROFILEDATA_INSTRPROFCORRELATOR_H
|
| 13 |
+
#define LLVM_PROFILEDATA_INSTRPROFCORRELATOR_H
|
| 14 |
+
|
| 15 |
+
#include "llvm/ADT/DenseSet.h"
|
| 16 |
+
#include "llvm/Debuginfod/BuildIDFetcher.h"
|
| 17 |
+
#include "llvm/Object/BuildID.h"
|
| 18 |
+
#include "llvm/ProfileData/InstrProf.h"
|
| 19 |
+
#include "llvm/Support/Error.h"
|
| 20 |
+
#include "llvm/Support/MemoryBuffer.h"
|
| 21 |
+
#include "llvm/Support/YAMLTraits.h"
|
| 22 |
+
#include <optional>
|
| 23 |
+
#include <vector>
|
| 24 |
+
|
| 25 |
+
namespace llvm {
|
| 26 |
+
class DWARFContext;
|
| 27 |
+
class DWARFDie;
|
| 28 |
+
namespace object {
|
| 29 |
+
class ObjectFile;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
/// InstrProfCorrelator - A base class used to create raw instrumentation data
|
| 33 |
+
/// to their functions.
|
| 34 |
+
class InstrProfCorrelator {
|
| 35 |
+
public:
|
| 36 |
+
/// Indicate if we should use the debug info or profile metadata sections to
|
| 37 |
+
/// correlate.
|
| 38 |
+
enum ProfCorrelatorKind { NONE, DEBUG_INFO, BINARY };
|
| 39 |
+
|
| 40 |
+
static llvm::Expected<std::unique_ptr<InstrProfCorrelator>>
|
| 41 |
+
get(StringRef Filename, ProfCorrelatorKind FileKind,
|
| 42 |
+
const object::BuildIDFetcher *BIDFetcher = nullptr,
|
| 43 |
+
const ArrayRef<llvm::object::BuildID> BIs = {});
|
| 44 |
+
|
| 45 |
+
/// Construct a ProfileData vector used to correlate raw instrumentation data
|
| 46 |
+
/// to their functions.
|
| 47 |
+
/// \param MaxWarnings the maximum number of warnings to emit (0 = no limit)
|
| 48 |
+
virtual Error correlateProfileData(int MaxWarnings) = 0;
|
| 49 |
+
|
| 50 |
+
/// Process debug info and dump the correlation data.
|
| 51 |
+
/// \param MaxWarnings the maximum number of warnings to emit (0 = no limit)
|
| 52 |
+
virtual Error dumpYaml(int MaxWarnings, raw_ostream &OS) = 0;
|
| 53 |
+
|
| 54 |
+
/// Return the number of ProfileData elements.
|
| 55 |
+
std::optional<size_t> getDataSize() const;
|
| 56 |
+
|
| 57 |
+
/// Return a pointer to the names string that this class constructs.
|
| 58 |
+
const char *getNamesPointer() const { return Names.c_str(); }
|
| 59 |
+
|
| 60 |
+
/// Return the number of bytes in the names string.
|
| 61 |
+
size_t getNamesSize() const { return Names.size(); }
|
| 62 |
+
|
| 63 |
+
/// Return the size of the counters section in bytes.
|
| 64 |
+
uint64_t getCountersSectionSize() const {
|
| 65 |
+
return Ctx->CountersSectionEnd - Ctx->CountersSectionStart;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
static const char *FunctionNameAttributeName;
|
| 69 |
+
static const char *CFGHashAttributeName;
|
| 70 |
+
static const char *NumCountersAttributeName;
|
| 71 |
+
|
| 72 |
+
enum InstrProfCorrelatorKind { CK_32Bit, CK_64Bit };
|
| 73 |
+
InstrProfCorrelatorKind getKind() const { return Kind; }
|
| 74 |
+
virtual ~InstrProfCorrelator() = default;
|
| 75 |
+
|
| 76 |
+
protected:
|
| 77 |
+
struct Context {
|
| 78 |
+
static llvm::Expected<std::unique_ptr<Context>>
|
| 79 |
+
get(std::unique_ptr<MemoryBuffer> Buffer, const object::ObjectFile &Obj,
|
| 80 |
+
ProfCorrelatorKind FileKind);
|
| 81 |
+
std::unique_ptr<MemoryBuffer> Buffer;
|
| 82 |
+
/// The address range of the __llvm_prf_cnts section.
|
| 83 |
+
uint64_t CountersSectionStart;
|
| 84 |
+
uint64_t CountersSectionEnd;
|
| 85 |
+
/// The pointer points to start/end of profile data/name sections if
|
| 86 |
+
/// FileKind is Binary.
|
| 87 |
+
const char *DataStart;
|
| 88 |
+
const char *DataEnd;
|
| 89 |
+
const char *NameStart;
|
| 90 |
+
size_t NameSize;
|
| 91 |
+
/// True if target and host have different endian orders.
|
| 92 |
+
bool ShouldSwapBytes;
|
| 93 |
+
};
|
| 94 |
+
const std::unique_ptr<Context> Ctx;
|
| 95 |
+
|
| 96 |
+
InstrProfCorrelator(InstrProfCorrelatorKind K, std::unique_ptr<Context> Ctx)
|
| 97 |
+
: Ctx(std::move(Ctx)), Kind(K) {}
|
| 98 |
+
|
| 99 |
+
std::string Names;
|
| 100 |
+
std::vector<std::string> NamesVec;
|
| 101 |
+
|
| 102 |
+
struct Probe {
|
| 103 |
+
std::string FunctionName;
|
| 104 |
+
std::optional<std::string> LinkageName;
|
| 105 |
+
yaml::Hex64 CFGHash;
|
| 106 |
+
yaml::Hex64 CounterOffset;
|
| 107 |
+
uint32_t NumCounters;
|
| 108 |
+
std::optional<std::string> FilePath;
|
| 109 |
+
std::optional<int> LineNumber;
|
| 110 |
+
};
|
| 111 |
+
|
| 112 |
+
struct CorrelationData {
|
| 113 |
+
std::vector<Probe> Probes;
|
| 114 |
+
};
|
| 115 |
+
|
| 116 |
+
friend struct yaml::MappingTraits<Probe>;
|
| 117 |
+
friend struct yaml::SequenceElementTraits<Probe>;
|
| 118 |
+
friend struct yaml::MappingTraits<CorrelationData>;
|
| 119 |
+
|
| 120 |
+
private:
|
| 121 |
+
static llvm::Expected<std::unique_ptr<InstrProfCorrelator>>
|
| 122 |
+
get(std::unique_ptr<MemoryBuffer> Buffer, ProfCorrelatorKind FileKind);
|
| 123 |
+
|
| 124 |
+
const InstrProfCorrelatorKind Kind;
|
| 125 |
+
};
|
| 126 |
+
|
| 127 |
+
/// InstrProfCorrelatorImpl - A child of InstrProfCorrelator with a template
|
| 128 |
+
/// pointer type so that the ProfileData vector can be materialized.
|
| 129 |
+
template <class IntPtrT>
|
| 130 |
+
class InstrProfCorrelatorImpl : public InstrProfCorrelator {
|
| 131 |
+
public:
|
| 132 |
+
InstrProfCorrelatorImpl(std::unique_ptr<InstrProfCorrelator::Context> Ctx);
|
| 133 |
+
static bool classof(const InstrProfCorrelator *C);
|
| 134 |
+
|
| 135 |
+
/// Return a pointer to the underlying ProfileData vector that this class
|
| 136 |
+
/// constructs.
|
| 137 |
+
const RawInstrProf::ProfileData<IntPtrT> *getDataPointer() const {
|
| 138 |
+
return Data.empty() ? nullptr : Data.data();
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
/// Return the number of ProfileData elements.
|
| 142 |
+
size_t getDataSize() const { return Data.size(); }
|
| 143 |
+
|
| 144 |
+
static llvm::Expected<std::unique_ptr<InstrProfCorrelatorImpl<IntPtrT>>>
|
| 145 |
+
get(std::unique_ptr<InstrProfCorrelator::Context> Ctx,
|
| 146 |
+
const object::ObjectFile &Obj, ProfCorrelatorKind FileKind);
|
| 147 |
+
|
| 148 |
+
protected:
|
| 149 |
+
std::vector<RawInstrProf::ProfileData<IntPtrT>> Data;
|
| 150 |
+
|
| 151 |
+
Error correlateProfileData(int MaxWarnings) override;
|
| 152 |
+
virtual void correlateProfileDataImpl(
|
| 153 |
+
int MaxWarnings,
|
| 154 |
+
InstrProfCorrelator::CorrelationData *Data = nullptr) = 0;
|
| 155 |
+
|
| 156 |
+
virtual Error correlateProfileNameImpl() = 0;
|
| 157 |
+
|
| 158 |
+
Error dumpYaml(int MaxWarnings, raw_ostream &OS) override;
|
| 159 |
+
|
| 160 |
+
void addDataProbe(uint64_t FunctionName, uint64_t CFGHash,
|
| 161 |
+
IntPtrT CounterOffset, IntPtrT FunctionPtr,
|
| 162 |
+
uint32_t NumCounters);
|
| 163 |
+
|
| 164 |
+
// Byte-swap the value if necessary.
|
| 165 |
+
template <class T> T maybeSwap(T Value) const {
|
| 166 |
+
return Ctx->ShouldSwapBytes ? llvm::byteswap(Value) : Value;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
private:
|
| 170 |
+
InstrProfCorrelatorImpl(InstrProfCorrelatorKind Kind,
|
| 171 |
+
std::unique_ptr<InstrProfCorrelator::Context> Ctx)
|
| 172 |
+
: InstrProfCorrelator(Kind, std::move(Ctx)){};
|
| 173 |
+
llvm::DenseSet<IntPtrT> CounterOffsets;
|
| 174 |
+
};
|
| 175 |
+
|
| 176 |
+
/// DwarfInstrProfCorrelator - A child of InstrProfCorrelatorImpl that takes
|
| 177 |
+
/// DWARF debug info as input to correlate profiles.
|
| 178 |
+
template <class IntPtrT>
|
| 179 |
+
class DwarfInstrProfCorrelator : public InstrProfCorrelatorImpl<IntPtrT> {
|
| 180 |
+
public:
|
| 181 |
+
DwarfInstrProfCorrelator(std::unique_ptr<DWARFContext> DICtx,
|
| 182 |
+
std::unique_ptr<InstrProfCorrelator::Context> Ctx)
|
| 183 |
+
: InstrProfCorrelatorImpl<IntPtrT>(std::move(Ctx)),
|
| 184 |
+
DICtx(std::move(DICtx)) {}
|
| 185 |
+
|
| 186 |
+
private:
|
| 187 |
+
std::unique_ptr<DWARFContext> DICtx;
|
| 188 |
+
|
| 189 |
+
/// Return the address of the object that the provided DIE symbolizes.
|
| 190 |
+
std::optional<uint64_t> getLocation(const DWARFDie &Die) const;
|
| 191 |
+
|
| 192 |
+
/// Returns true if the provided DIE symbolizes an instrumentation probe
|
| 193 |
+
/// symbol.
|
| 194 |
+
static bool isDIEOfProbe(const DWARFDie &Die);
|
| 195 |
+
|
| 196 |
+
/// Iterate over DWARF DIEs to find those that symbolize instrumentation
|
| 197 |
+
/// probes and construct the ProfileData vector and Names string.
|
| 198 |
+
///
|
| 199 |
+
/// Here is some example DWARF for an instrumentation probe we are looking
|
| 200 |
+
/// for:
|
| 201 |
+
/// \code
|
| 202 |
+
/// DW_TAG_subprogram
|
| 203 |
+
/// DW_AT_low_pc (0x0000000000000000)
|
| 204 |
+
/// DW_AT_high_pc (0x0000000000000014)
|
| 205 |
+
/// DW_AT_name ("foo")
|
| 206 |
+
/// DW_TAG_variable
|
| 207 |
+
/// DW_AT_name ("__profc_foo")
|
| 208 |
+
/// DW_AT_location (DW_OP_addr 0x0)
|
| 209 |
+
/// DW_TAG_LLVM_annotation
|
| 210 |
+
/// DW_AT_name ("Function Name")
|
| 211 |
+
/// DW_AT_const_value ("foo")
|
| 212 |
+
/// DW_TAG_LLVM_annotation
|
| 213 |
+
/// DW_AT_name ("CFG Hash")
|
| 214 |
+
/// DW_AT_const_value (12345678)
|
| 215 |
+
/// DW_TAG_LLVM_annotation
|
| 216 |
+
/// DW_AT_name ("Num Counters")
|
| 217 |
+
/// DW_AT_const_value (2)
|
| 218 |
+
/// NULL
|
| 219 |
+
/// NULL
|
| 220 |
+
/// \endcode
|
| 221 |
+
/// \param MaxWarnings the maximum number of warnings to emit (0 = no limit)
|
| 222 |
+
/// \param Data if provided, populate with the correlation data found
|
| 223 |
+
void correlateProfileDataImpl(
|
| 224 |
+
int MaxWarnings,
|
| 225 |
+
InstrProfCorrelator::CorrelationData *Data = nullptr) override;
|
| 226 |
+
|
| 227 |
+
Error correlateProfileNameImpl() override;
|
| 228 |
+
};
|
| 229 |
+
|
| 230 |
+
/// BinaryInstrProfCorrelator - A child of InstrProfCorrelatorImpl that
|
| 231 |
+
/// takes an object file as input to correlate profiles.
|
| 232 |
+
template <class IntPtrT>
|
| 233 |
+
class BinaryInstrProfCorrelator : public InstrProfCorrelatorImpl<IntPtrT> {
|
| 234 |
+
public:
|
| 235 |
+
BinaryInstrProfCorrelator(std::unique_ptr<InstrProfCorrelator::Context> Ctx)
|
| 236 |
+
: InstrProfCorrelatorImpl<IntPtrT>(std::move(Ctx)) {}
|
| 237 |
+
|
| 238 |
+
/// Return a pointer to the names string that this class constructs.
|
| 239 |
+
const char *getNamesPointer() const { return this->Ctx.NameStart; }
|
| 240 |
+
|
| 241 |
+
/// Return the number of bytes in the names string.
|
| 242 |
+
size_t getNamesSize() const { return this->Ctx.NameSize; }
|
| 243 |
+
|
| 244 |
+
private:
|
| 245 |
+
void correlateProfileDataImpl(
|
| 246 |
+
int MaxWarnings,
|
| 247 |
+
InstrProfCorrelator::CorrelationData *Data = nullptr) override;
|
| 248 |
+
|
| 249 |
+
Error correlateProfileNameImpl() override;
|
| 250 |
+
};
|
| 251 |
+
|
| 252 |
+
} // end namespace llvm
|
| 253 |
+
|
| 254 |
+
#endif // LLVM_PROFILEDATA_INSTRPROFCORRELATOR_H
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/InstrProfData.inc
ADDED
|
@@ -0,0 +1,1001 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*===-- InstrProfData.inc - instr profiling runtime structures -*- C++ -*-=== *\
|
| 2 |
+
|*
|
| 3 |
+
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
|* See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
|*
|
| 7 |
+
\*===----------------------------------------------------------------------===*/
|
| 8 |
+
/*
|
| 9 |
+
* This is the main file that defines all the data structure, signature,
|
| 10 |
+
* constant literals that are shared across profiling runtime library,
|
| 11 |
+
* compiler (instrumentation), and host tools (reader/writer). The entities
|
| 12 |
+
* defined in this file affect the profile runtime ABI, the raw profile format,
|
| 13 |
+
* or both.
|
| 14 |
+
*
|
| 15 |
+
* The file has two identical copies. The primary copy lives in LLVM and
|
| 16 |
+
* the other one sits in compiler-rt/lib/profile directory. To make changes
|
| 17 |
+
* in this file, first modify the primary copy and copy it over to compiler-rt.
|
| 18 |
+
* Testing of any change in this file can start only after the two copies are
|
| 19 |
+
* synced up.
|
| 20 |
+
*
|
| 21 |
+
* The first part of the file includes macros that defines types, names, and
|
| 22 |
+
* initializers for the member fields of the core data structures. The field
|
| 23 |
+
* declarations for one structure is enabled by defining the field activation
|
| 24 |
+
* macro associated with that structure. Only one field activation record
|
| 25 |
+
* can be defined at one time and the rest definitions will be filtered out by
|
| 26 |
+
* the preprocessor.
|
| 27 |
+
*
|
| 28 |
+
* Examples of how the template is used to instantiate structure definition:
|
| 29 |
+
* 1. To declare a structure:
|
| 30 |
+
*
|
| 31 |
+
* struct ProfData {
|
| 32 |
+
* #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
|
| 33 |
+
* Type Name;
|
| 34 |
+
* #include "llvm/ProfileData/InstrProfData.inc"
|
| 35 |
+
* };
|
| 36 |
+
*
|
| 37 |
+
* 2. To construct LLVM type arrays for the struct type:
|
| 38 |
+
*
|
| 39 |
+
* Type *DataTypes[] = {
|
| 40 |
+
* #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
|
| 41 |
+
* LLVMType,
|
| 42 |
+
* #include "llvm/ProfileData/InstrProfData.inc"
|
| 43 |
+
* };
|
| 44 |
+
*
|
| 45 |
+
* 4. To construct constant array for the initializers:
|
| 46 |
+
* #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
|
| 47 |
+
* Initializer,
|
| 48 |
+
* Constant *ConstantVals[] = {
|
| 49 |
+
* #include "llvm/ProfileData/InstrProfData.inc"
|
| 50 |
+
* };
|
| 51 |
+
*
|
| 52 |
+
*
|
| 53 |
+
* The second part of the file includes definitions all other entities that
|
| 54 |
+
* are related to runtime ABI and format. When no field activation macro is
|
| 55 |
+
* defined, this file can be included to introduce the definitions.
|
| 56 |
+
*
|
| 57 |
+
\*===----------------------------------------------------------------------===*/
|
| 58 |
+
|
| 59 |
+
/* Functions marked with INSTR_PROF_VISIBILITY must have hidden visibility in
|
| 60 |
+
* the compiler runtime. */
|
| 61 |
+
#ifndef INSTR_PROF_VISIBILITY
|
| 62 |
+
#define INSTR_PROF_VISIBILITY
|
| 63 |
+
#endif
|
| 64 |
+
|
| 65 |
+
// clang-format off:consider re-enabling clang-format if auto-formatted C macros
|
| 66 |
+
// are readable (e.g., after `issue #82426` is fixed)
|
| 67 |
+
/* INSTR_PROF_DATA start. */
|
| 68 |
+
/* Definition of member fields of the per-function control structure. */
|
| 69 |
+
#ifndef INSTR_PROF_DATA
|
| 70 |
+
#define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer)
|
| 71 |
+
#else
|
| 72 |
+
#define INSTR_PROF_DATA_DEFINED
|
| 73 |
+
#endif
|
| 74 |
+
INSTR_PROF_DATA(const uint64_t, llvm::Type::getInt64Ty(Ctx), NameRef, \
|
| 75 |
+
ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
|
| 76 |
+
IndexedInstrProf::ComputeHash(getPGOFuncNameVarInitializer(Inc->getName()))))
|
| 77 |
+
INSTR_PROF_DATA(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
|
| 78 |
+
ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
|
| 79 |
+
Inc->getHash()->getZExtValue()))
|
| 80 |
+
INSTR_PROF_DATA(const IntPtrT, IntPtrTy, CounterPtr, RelativeCounterPtr)
|
| 81 |
+
INSTR_PROF_DATA(const IntPtrT, IntPtrTy, BitmapPtr, RelativeBitmapPtr)
|
| 82 |
+
/* This is used to map function pointers for the indirect call targets to
|
| 83 |
+
* function name hashes during the conversion from raw to merged profile
|
| 84 |
+
* data.
|
| 85 |
+
*/
|
| 86 |
+
INSTR_PROF_DATA(const IntPtrT, llvm::PointerType::getUnqual(Ctx), FunctionPointer, \
|
| 87 |
+
FunctionAddr)
|
| 88 |
+
INSTR_PROF_DATA(IntPtrT, llvm::PointerType::getUnqual(Ctx), Values, \
|
| 89 |
+
ValuesPtrExpr)
|
| 90 |
+
INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NumCounters, \
|
| 91 |
+
ConstantInt::get(llvm::Type::getInt32Ty(Ctx), NumCounters))
|
| 92 |
+
INSTR_PROF_DATA(const uint16_t, Int16ArrayTy, NumValueSites[IPVK_Last+1], \
|
| 93 |
+
ConstantArray::get(Int16ArrayTy, Int16ArrayVals)) \
|
| 94 |
+
INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NumBitmapBytes, \
|
| 95 |
+
ConstantInt::get(llvm::Type::getInt32Ty(Ctx), NumBitmapBytes))
|
| 96 |
+
#undef INSTR_PROF_DATA
|
| 97 |
+
/* INSTR_PROF_DATA end. */
|
| 98 |
+
|
| 99 |
+
/* For a virtual table object, record the name hash to associate profiled
|
| 100 |
+
* addresses with global variables, and record {starting address, size in bytes}
|
| 101 |
+
* to map the profiled virtual table (which usually have an offset from the
|
| 102 |
+
* starting address) back to a virtual table object. */
|
| 103 |
+
#ifndef INSTR_PROF_VTABLE_DATA
|
| 104 |
+
#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Initializer)
|
| 105 |
+
#else
|
| 106 |
+
#define INSTR_PROF_VTABLE_DATA_DEFINED
|
| 107 |
+
#endif
|
| 108 |
+
INSTR_PROF_VTABLE_DATA(const uint64_t, llvm::Type::getInt64Ty(Ctx), \
|
| 109 |
+
VTableNameHash, ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
|
| 110 |
+
IndexedInstrProf::ComputeHash(PGOVTableName)))
|
| 111 |
+
INSTR_PROF_VTABLE_DATA(const IntPtrT, llvm::PointerType::getUnqual(Ctx), \
|
| 112 |
+
VTablePointer, VTableAddr)
|
| 113 |
+
INSTR_PROF_VTABLE_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), VTableSize, \
|
| 114 |
+
ConstantInt::get(llvm::Type::getInt32Ty(Ctx), \
|
| 115 |
+
VTableSizeVal))
|
| 116 |
+
#undef INSTR_PROF_VTABLE_DATA
|
| 117 |
+
/* INSTR_PROF_VTABLE_DATA end. */
|
| 118 |
+
|
| 119 |
+
/* This is an internal data structure used by value profiler. It
|
| 120 |
+
* is defined here to allow serialization code sharing by LLVM
|
| 121 |
+
* to be used in unit test.
|
| 122 |
+
*
|
| 123 |
+
* typedef struct ValueProfNode {
|
| 124 |
+
* // InstrProfValueData VData;
|
| 125 |
+
* uint64_t Value;
|
| 126 |
+
* uint64_t Count;
|
| 127 |
+
* struct ValueProfNode *Next;
|
| 128 |
+
* } ValueProfNode;
|
| 129 |
+
*/
|
| 130 |
+
/* INSTR_PROF_VALUE_NODE start. */
|
| 131 |
+
#ifndef INSTR_PROF_VALUE_NODE
|
| 132 |
+
#define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Initializer)
|
| 133 |
+
#else
|
| 134 |
+
#define INSTR_PROF_DATA_DEFINED
|
| 135 |
+
#endif
|
| 136 |
+
INSTR_PROF_VALUE_NODE(uint64_t, llvm::Type::getInt64Ty(Ctx), Value, \
|
| 137 |
+
ConstantInt::get(llvm::Type::GetInt64Ty(Ctx), 0))
|
| 138 |
+
INSTR_PROF_VALUE_NODE(uint64_t, llvm::Type::getInt64Ty(Ctx), Count, \
|
| 139 |
+
ConstantInt::get(llvm::Type::GetInt64Ty(Ctx), 0))
|
| 140 |
+
INSTR_PROF_VALUE_NODE(PtrToNodeT, llvm::PointerType::getUnqual(Ctx), Next, \
|
| 141 |
+
ConstantInt::get(llvm::PointerType::getUnqual(Ctx), 0))
|
| 142 |
+
#undef INSTR_PROF_VALUE_NODE
|
| 143 |
+
/* INSTR_PROF_VALUE_NODE end. */
|
| 144 |
+
|
| 145 |
+
/* INSTR_PROF_RAW_HEADER start */
|
| 146 |
+
/* Definition of member fields of the raw profile header data structure. */
|
| 147 |
+
/* Please update llvm/docs/InstrProfileFormat.rst as appropriate when updating
|
| 148 |
+
raw profile format. */
|
| 149 |
+
#ifndef INSTR_PROF_RAW_HEADER
|
| 150 |
+
#define INSTR_PROF_RAW_HEADER(Type, Name, Initializer)
|
| 151 |
+
#else
|
| 152 |
+
#define INSTR_PROF_DATA_DEFINED
|
| 153 |
+
#endif
|
| 154 |
+
INSTR_PROF_RAW_HEADER(uint64_t, Magic, __llvm_profile_get_magic())
|
| 155 |
+
INSTR_PROF_RAW_HEADER(uint64_t, Version, __llvm_profile_get_version())
|
| 156 |
+
INSTR_PROF_RAW_HEADER(uint64_t, BinaryIdsSize, __llvm_write_binary_ids(NULL))
|
| 157 |
+
INSTR_PROF_RAW_HEADER(uint64_t, NumData, NumData)
|
| 158 |
+
INSTR_PROF_RAW_HEADER(uint64_t, PaddingBytesBeforeCounters, PaddingBytesBeforeCounters)
|
| 159 |
+
INSTR_PROF_RAW_HEADER(uint64_t, NumCounters, NumCounters)
|
| 160 |
+
INSTR_PROF_RAW_HEADER(uint64_t, PaddingBytesAfterCounters, PaddingBytesAfterCounters)
|
| 161 |
+
INSTR_PROF_RAW_HEADER(uint64_t, NumBitmapBytes, NumBitmapBytes)
|
| 162 |
+
INSTR_PROF_RAW_HEADER(uint64_t, PaddingBytesAfterBitmapBytes, PaddingBytesAfterBitmapBytes)
|
| 163 |
+
INSTR_PROF_RAW_HEADER(uint64_t, NamesSize, NamesSize)
|
| 164 |
+
INSTR_PROF_RAW_HEADER(uint64_t, CountersDelta,
|
| 165 |
+
(uintptr_t)CountersBegin - (uintptr_t)DataBegin)
|
| 166 |
+
INSTR_PROF_RAW_HEADER(uint64_t, BitmapDelta,
|
| 167 |
+
(uintptr_t)BitmapBegin - (uintptr_t)DataBegin)
|
| 168 |
+
INSTR_PROF_RAW_HEADER(uint64_t, NamesDelta, (uintptr_t)NamesBegin)
|
| 169 |
+
INSTR_PROF_RAW_HEADER(uint64_t, NumVTables, NumVTables)
|
| 170 |
+
INSTR_PROF_RAW_HEADER(uint64_t, VNamesSize, VNamesSize)
|
| 171 |
+
INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
|
| 172 |
+
#undef INSTR_PROF_RAW_HEADER
|
| 173 |
+
/* INSTR_PROF_RAW_HEADER end */
|
| 174 |
+
|
| 175 |
+
/* VALUE_PROF_FUNC_PARAM start */
|
| 176 |
+
/* Definition of parameter types of the runtime API used to do value profiling
|
| 177 |
+
* for a given value site.
|
| 178 |
+
*/
|
| 179 |
+
#ifndef VALUE_PROF_FUNC_PARAM
|
| 180 |
+
#define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType)
|
| 181 |
+
#define INSTR_PROF_COMMA
|
| 182 |
+
#else
|
| 183 |
+
#define INSTR_PROF_DATA_DEFINED
|
| 184 |
+
#define INSTR_PROF_COMMA ,
|
| 185 |
+
#endif
|
| 186 |
+
VALUE_PROF_FUNC_PARAM(uint64_t, TargetValue, Type::getInt64Ty(Ctx)) \
|
| 187 |
+
INSTR_PROF_COMMA
|
| 188 |
+
VALUE_PROF_FUNC_PARAM(void *, Data, PointerType::getUnqual(Ctx)) INSTR_PROF_COMMA
|
| 189 |
+
VALUE_PROF_FUNC_PARAM(uint32_t, CounterIndex, Type::getInt32Ty(Ctx))
|
| 190 |
+
#undef VALUE_PROF_FUNC_PARAM
|
| 191 |
+
#undef INSTR_PROF_COMMA
|
| 192 |
+
/* VALUE_PROF_FUNC_PARAM end */
|
| 193 |
+
|
| 194 |
+
/* VALUE_PROF_KIND start */
|
| 195 |
+
#ifndef VALUE_PROF_KIND
|
| 196 |
+
#define VALUE_PROF_KIND(Enumerator, Value, Descr)
|
| 197 |
+
#else
|
| 198 |
+
#define INSTR_PROF_DATA_DEFINED
|
| 199 |
+
#endif
|
| 200 |
+
/* For indirect function call value profiling, the addresses of the target
|
| 201 |
+
* functions are profiled by the instrumented code. The target addresses are
|
| 202 |
+
* written in the raw profile data and converted to target function name's MD5
|
| 203 |
+
* hash by the profile reader during deserialization. Typically, this happens
|
| 204 |
+
* when the raw profile data is read during profile merging.
|
| 205 |
+
*
|
| 206 |
+
* For this remapping the ProfData is used. ProfData contains both the function
|
| 207 |
+
* name hash and the function address.
|
| 208 |
+
*/
|
| 209 |
+
VALUE_PROF_KIND(IPVK_IndirectCallTarget, 0, "indirect call target")
|
| 210 |
+
/* For memory intrinsic functions size profiling. */
|
| 211 |
+
VALUE_PROF_KIND(IPVK_MemOPSize, 1, "memory intrinsic functions size")
|
| 212 |
+
/* For virtual table address profiling, the address point of the virtual table
|
| 213 |
+
* (i.e., the address contained in objects pointing to a virtual table) are
|
| 214 |
+
* profiled. Note this may not be the address of the per C++ class virtual table
|
| 215 |
+
* object (e.g., there might be an offset).
|
| 216 |
+
*
|
| 217 |
+
* The profiled addresses are stored in raw profile, together with the following
|
| 218 |
+
* two types of information.
|
| 219 |
+
* 1. The (starting and ending) addresses of per C++ class virtual table objects.
|
| 220 |
+
* 2. The (compressed) virtual table object names.
|
| 221 |
+
* RawInstrProfReader converts profiled virtual table addresses to virtual table
|
| 222 |
+
* objects' MD5 hash.
|
| 223 |
+
*/
|
| 224 |
+
VALUE_PROF_KIND(IPVK_VTableTarget, 2, "The profiled address point of the vtable")
|
| 225 |
+
/* These two kinds must be the last to be
|
| 226 |
+
* declared. This is to make sure the string
|
| 227 |
+
* array created with the template can be
|
| 228 |
+
* indexed with the kind value.
|
| 229 |
+
*/
|
| 230 |
+
VALUE_PROF_KIND(IPVK_First, IPVK_IndirectCallTarget, "first")
|
| 231 |
+
VALUE_PROF_KIND(IPVK_Last, IPVK_VTableTarget, "last")
|
| 232 |
+
|
| 233 |
+
#undef VALUE_PROF_KIND
|
| 234 |
+
/* VALUE_PROF_KIND end */
|
| 235 |
+
|
| 236 |
+
#undef COVMAP_V2_OR_V3
|
| 237 |
+
#ifdef COVMAP_V2
|
| 238 |
+
#define COVMAP_V2_OR_V3
|
| 239 |
+
#endif
|
| 240 |
+
#ifdef COVMAP_V3
|
| 241 |
+
#define COVMAP_V2_OR_V3
|
| 242 |
+
#endif
|
| 243 |
+
|
| 244 |
+
/* COVMAP_FUNC_RECORD start */
|
| 245 |
+
/* Definition of member fields of the function record structure in coverage
|
| 246 |
+
* map.
|
| 247 |
+
*/
|
| 248 |
+
#ifndef COVMAP_FUNC_RECORD
|
| 249 |
+
#define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Initializer)
|
| 250 |
+
#else
|
| 251 |
+
#define INSTR_PROF_DATA_DEFINED
|
| 252 |
+
#endif
|
| 253 |
+
#ifdef COVMAP_V1
|
| 254 |
+
COVMAP_FUNC_RECORD(const IntPtrT, llvm::PointerType::getUnqual(Ctx), \
|
| 255 |
+
NamePtr, llvm::ConstantExpr::getBitCast(NamePtr, \
|
| 256 |
+
llvm::PointerType::getUnqual(Ctx)))
|
| 257 |
+
COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), NameSize, \
|
| 258 |
+
llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), \
|
| 259 |
+
NameValue.size()))
|
| 260 |
+
#endif
|
| 261 |
+
#ifdef COVMAP_V2_OR_V3
|
| 262 |
+
COVMAP_FUNC_RECORD(const int64_t, llvm::Type::getInt64Ty(Ctx), NameRef, \
|
| 263 |
+
llvm::ConstantInt::get( \
|
| 264 |
+
llvm::Type::getInt64Ty(Ctx), NameHash))
|
| 265 |
+
#endif
|
| 266 |
+
COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), DataSize, \
|
| 267 |
+
llvm::ConstantInt::get( \
|
| 268 |
+
llvm::Type::getInt32Ty(Ctx), CoverageMapping.size()))
|
| 269 |
+
COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \
|
| 270 |
+
llvm::ConstantInt::get( \
|
| 271 |
+
llvm::Type::getInt64Ty(Ctx), FuncHash))
|
| 272 |
+
#ifdef COVMAP_V3
|
| 273 |
+
COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FilenamesRef, \
|
| 274 |
+
llvm::ConstantInt::get( \
|
| 275 |
+
llvm::Type::getInt64Ty(Ctx), FilenamesRef))
|
| 276 |
+
COVMAP_FUNC_RECORD(const char, \
|
| 277 |
+
llvm::ArrayType::get(llvm::Type::getInt8Ty(Ctx), \
|
| 278 |
+
CoverageMapping.size()), \
|
| 279 |
+
CoverageMapping,
|
| 280 |
+
llvm::ConstantDataArray::getRaw( \
|
| 281 |
+
CoverageMapping, CoverageMapping.size(), \
|
| 282 |
+
llvm::Type::getInt8Ty(Ctx)))
|
| 283 |
+
#endif
|
| 284 |
+
#undef COVMAP_FUNC_RECORD
|
| 285 |
+
/* COVMAP_FUNC_RECORD end. */
|
| 286 |
+
|
| 287 |
+
/* COVMAP_HEADER start */
|
| 288 |
+
/* Definition of member fields of coverage map header.
|
| 289 |
+
*/
|
| 290 |
+
#ifndef COVMAP_HEADER
|
| 291 |
+
#define COVMAP_HEADER(Type, LLVMType, Name, Initializer)
|
| 292 |
+
#else
|
| 293 |
+
#define INSTR_PROF_DATA_DEFINED
|
| 294 |
+
#endif
|
| 295 |
+
COVMAP_HEADER(uint32_t, Int32Ty, NRecords, \
|
| 296 |
+
llvm::ConstantInt::get(Int32Ty, NRecords))
|
| 297 |
+
COVMAP_HEADER(uint32_t, Int32Ty, FilenamesSize, \
|
| 298 |
+
llvm::ConstantInt::get(Int32Ty, FilenamesSize))
|
| 299 |
+
COVMAP_HEADER(uint32_t, Int32Ty, CoverageSize, \
|
| 300 |
+
llvm::ConstantInt::get(Int32Ty, CoverageMappingSize))
|
| 301 |
+
COVMAP_HEADER(uint32_t, Int32Ty, Version, \
|
| 302 |
+
llvm::ConstantInt::get(Int32Ty, CovMapVersion::CurrentVersion))
|
| 303 |
+
#undef COVMAP_HEADER
|
| 304 |
+
/* COVMAP_HEADER end. */
|
| 305 |
+
|
| 306 |
+
/* COVINIT_FUNC start */
|
| 307 |
+
#ifndef COVINIT_FUNC
|
| 308 |
+
#define COVINIT_FUNC(Type, LLVMType, Name, Initializer)
|
| 309 |
+
#else
|
| 310 |
+
#define INSTR_PROF_DATA_DEFINED
|
| 311 |
+
#endif
|
| 312 |
+
COVINIT_FUNC(IntPtrT, llvm::PointerType::getUnqual(Ctx), WriteoutFunction, \
|
| 313 |
+
WriteoutF)
|
| 314 |
+
COVINIT_FUNC(IntPtrT, llvm::PointerType::getUnqual(Ctx), ResetFunction, \
|
| 315 |
+
ResetF)
|
| 316 |
+
#undef COVINIT_FUNC
|
| 317 |
+
/* COVINIT_FUNC end */
|
| 318 |
+
|
| 319 |
+
#ifdef INSTR_PROF_SECT_ENTRY
|
| 320 |
+
#define INSTR_PROF_DATA_DEFINED
|
| 321 |
+
INSTR_PROF_SECT_ENTRY(IPSK_data, \
|
| 322 |
+
INSTR_PROF_QUOTE(INSTR_PROF_DATA_COMMON), \
|
| 323 |
+
INSTR_PROF_DATA_COFF, "__DATA,")
|
| 324 |
+
INSTR_PROF_SECT_ENTRY(IPSK_cnts, \
|
| 325 |
+
INSTR_PROF_QUOTE(INSTR_PROF_CNTS_COMMON), \
|
| 326 |
+
INSTR_PROF_CNTS_COFF, "__DATA,")
|
| 327 |
+
INSTR_PROF_SECT_ENTRY(IPSK_bitmap, \
|
| 328 |
+
INSTR_PROF_QUOTE(INSTR_PROF_BITS_COMMON), \
|
| 329 |
+
INSTR_PROF_BITS_COFF, "__DATA,")
|
| 330 |
+
INSTR_PROF_SECT_ENTRY(IPSK_name, \
|
| 331 |
+
INSTR_PROF_QUOTE(INSTR_PROF_NAME_COMMON), \
|
| 332 |
+
INSTR_PROF_NAME_COFF, "__DATA,")
|
| 333 |
+
INSTR_PROF_SECT_ENTRY(IPSK_vname, \
|
| 334 |
+
INSTR_PROF_QUOTE(INSTR_PROF_VNAME_COMMON), \
|
| 335 |
+
INSTR_PROF_VNAME_COFF, "__DATA,")
|
| 336 |
+
INSTR_PROF_SECT_ENTRY(IPSK_vals, \
|
| 337 |
+
INSTR_PROF_QUOTE(INSTR_PROF_VALS_COMMON), \
|
| 338 |
+
INSTR_PROF_VALS_COFF, "__DATA,")
|
| 339 |
+
INSTR_PROF_SECT_ENTRY(IPSK_vnodes, \
|
| 340 |
+
INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COMMON), \
|
| 341 |
+
INSTR_PROF_VNODES_COFF, "__DATA,")
|
| 342 |
+
INSTR_PROF_SECT_ENTRY(IPSK_vtab, \
|
| 343 |
+
INSTR_PROF_QUOTE(INSTR_PROF_VTAB_COMMON), \
|
| 344 |
+
INSTR_PROF_VTAB_COFF, "__DATA,")
|
| 345 |
+
INSTR_PROF_SECT_ENTRY(IPSK_covmap, \
|
| 346 |
+
INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_COMMON), \
|
| 347 |
+
INSTR_PROF_COVMAP_COFF, "__LLVM_COV,")
|
| 348 |
+
INSTR_PROF_SECT_ENTRY(IPSK_covfun, \
|
| 349 |
+
INSTR_PROF_QUOTE(INSTR_PROF_COVFUN_COMMON), \
|
| 350 |
+
INSTR_PROF_COVFUN_COFF, "__LLVM_COV,")
|
| 351 |
+
INSTR_PROF_SECT_ENTRY(IPSK_covdata, \
|
| 352 |
+
INSTR_PROF_QUOTE(INSTR_PROF_COVDATA_COMMON), \
|
| 353 |
+
INSTR_PROF_COVDATA_COFF, "__LLVM_COV,")
|
| 354 |
+
INSTR_PROF_SECT_ENTRY(IPSK_covname, \
|
| 355 |
+
INSTR_PROF_QUOTE(INSTR_PROF_COVNAME_COMMON), \
|
| 356 |
+
INSTR_PROF_COVNAME_COFF, "__LLVM_COV,")
|
| 357 |
+
INSTR_PROF_SECT_ENTRY(IPSK_covinit, \
|
| 358 |
+
INSTR_PROF_QUOTE(INSTR_PROF_COVINIT_COMMON), \
|
| 359 |
+
INSTR_PROF_COVINIT_COFF, "__LLVM_COV,")
|
| 360 |
+
|
| 361 |
+
#undef INSTR_PROF_SECT_ENTRY
|
| 362 |
+
#endif
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
#ifdef INSTR_PROF_VALUE_PROF_DATA
|
| 366 |
+
#define INSTR_PROF_DATA_DEFINED
|
| 367 |
+
|
| 368 |
+
#define INSTR_PROF_MAX_NUM_VAL_PER_SITE 255
|
| 369 |
+
/*!
|
| 370 |
+
* This is the header of the data structure that defines the on-disk
|
| 371 |
+
* layout of the value profile data of a particular kind for one function.
|
| 372 |
+
*/
|
| 373 |
+
typedef struct ValueProfRecord {
|
| 374 |
+
/* The kind of the value profile record. */
|
| 375 |
+
uint32_t Kind;
|
| 376 |
+
/*
|
| 377 |
+
* The number of value profile sites. It is guaranteed to be non-zero;
|
| 378 |
+
* otherwise the record for this kind won't be emitted.
|
| 379 |
+
*/
|
| 380 |
+
uint32_t NumValueSites;
|
| 381 |
+
/*
|
| 382 |
+
* The first element of the array that stores the number of profiled
|
| 383 |
+
* values for each value site. The size of the array is NumValueSites.
|
| 384 |
+
* Since NumValueSites is greater than zero, there is at least one
|
| 385 |
+
* element in the array.
|
| 386 |
+
*/
|
| 387 |
+
uint8_t SiteCountArray[1];
|
| 388 |
+
|
| 389 |
+
/*
|
| 390 |
+
* The fake declaration is for documentation purpose only.
|
| 391 |
+
* Align the start of next field to be on 8 byte boundaries.
|
| 392 |
+
uint8_t Padding[X];
|
| 393 |
+
*/
|
| 394 |
+
|
| 395 |
+
/* The array of value profile data. The size of the array is the sum
|
| 396 |
+
* of all elements in SiteCountArray[].
|
| 397 |
+
InstrProfValueData ValueData[];
|
| 398 |
+
*/
|
| 399 |
+
|
| 400 |
+
#ifdef __cplusplus
|
| 401 |
+
/*!
|
| 402 |
+
* Return the number of value sites.
|
| 403 |
+
*/
|
| 404 |
+
uint32_t getNumValueSites() const { return NumValueSites; }
|
| 405 |
+
/*!
|
| 406 |
+
* Read data from this record and save it to Record.
|
| 407 |
+
*/
|
| 408 |
+
void deserializeTo(InstrProfRecord &Record,
|
| 409 |
+
InstrProfSymtab *SymTab);
|
| 410 |
+
/*
|
| 411 |
+
* In-place byte swap:
|
| 412 |
+
* Do byte swap for this instance. \c Old is the original order before
|
| 413 |
+
* the swap, and \c New is the New byte order.
|
| 414 |
+
*/
|
| 415 |
+
void swapBytes(llvm::endianness Old, llvm::endianness New);
|
| 416 |
+
#endif
|
| 417 |
+
} ValueProfRecord;
|
| 418 |
+
|
| 419 |
+
/*!
|
| 420 |
+
* Per-function header/control data structure for value profiling
|
| 421 |
+
* data in indexed format.
|
| 422 |
+
*/
|
| 423 |
+
typedef struct ValueProfData {
|
| 424 |
+
/*
|
| 425 |
+
* Total size in bytes including this field. It must be a multiple
|
| 426 |
+
* of sizeof(uint64_t).
|
| 427 |
+
*/
|
| 428 |
+
uint32_t TotalSize;
|
| 429 |
+
/*
|
| 430 |
+
*The number of value profile kinds that has value profile data.
|
| 431 |
+
* In this implementation, a value profile kind is considered to
|
| 432 |
+
* have profile data if the number of value profile sites for the
|
| 433 |
+
* kind is not zero. More aggressively, the implementation can
|
| 434 |
+
* choose to check the actual data value: if none of the value sites
|
| 435 |
+
* has any profiled values, the kind can be skipped.
|
| 436 |
+
*/
|
| 437 |
+
uint32_t NumValueKinds;
|
| 438 |
+
|
| 439 |
+
/*
|
| 440 |
+
* Following are a sequence of variable length records. The prefix/header
|
| 441 |
+
* of each record is defined by ValueProfRecord type. The number of
|
| 442 |
+
* records is NumValueKinds.
|
| 443 |
+
* ValueProfRecord Record_1;
|
| 444 |
+
* ValueProfRecord Record_N;
|
| 445 |
+
*/
|
| 446 |
+
|
| 447 |
+
#if __cplusplus
|
| 448 |
+
/*!
|
| 449 |
+
* Return the total size in bytes of the on-disk value profile data
|
| 450 |
+
* given the data stored in Record.
|
| 451 |
+
*/
|
| 452 |
+
static uint32_t getSize(const InstrProfRecord &Record);
|
| 453 |
+
/*!
|
| 454 |
+
* Return a pointer to \c ValueProfData instance ready to be streamed.
|
| 455 |
+
*/
|
| 456 |
+
static std::unique_ptr<ValueProfData>
|
| 457 |
+
serializeFrom(const InstrProfRecord &Record);
|
| 458 |
+
/*!
|
| 459 |
+
* Check the integrity of the record.
|
| 460 |
+
*/
|
| 461 |
+
Error checkIntegrity();
|
| 462 |
+
/*!
|
| 463 |
+
* Return a pointer to \c ValueProfileData instance ready to be read.
|
| 464 |
+
* All data in the instance are properly byte swapped. The input
|
| 465 |
+
* data is assumed to be in little endian order.
|
| 466 |
+
*/
|
| 467 |
+
static Expected<std::unique_ptr<ValueProfData>>
|
| 468 |
+
getValueProfData(const unsigned char *SrcBuffer,
|
| 469 |
+
const unsigned char *const SrcBufferEnd,
|
| 470 |
+
llvm::endianness SrcDataEndianness);
|
| 471 |
+
/*!
|
| 472 |
+
* Swap byte order from \c Endianness order to host byte order.
|
| 473 |
+
*/
|
| 474 |
+
void swapBytesToHost(llvm::endianness Endianness);
|
| 475 |
+
/*!
|
| 476 |
+
* Swap byte order from host byte order to \c Endianness order.
|
| 477 |
+
*/
|
| 478 |
+
void swapBytesFromHost(llvm::endianness Endianness);
|
| 479 |
+
/*!
|
| 480 |
+
* Return the total size of \c ValueProfileData.
|
| 481 |
+
*/
|
| 482 |
+
uint32_t getSize() const { return TotalSize; }
|
| 483 |
+
/*!
|
| 484 |
+
* Read data from this data and save it to \c Record.
|
| 485 |
+
*/
|
| 486 |
+
void deserializeTo(InstrProfRecord &Record,
|
| 487 |
+
InstrProfSymtab *SymTab);
|
| 488 |
+
void operator delete(void *ptr) { ::operator delete(ptr); }
|
| 489 |
+
#endif
|
| 490 |
+
} ValueProfData;
|
| 491 |
+
|
| 492 |
+
/*
|
| 493 |
+
* The closure is designed to abstract away two types of value profile data:
|
| 494 |
+
* - InstrProfRecord which is the primary data structure used to
|
| 495 |
+
* represent profile data in host tools (reader, writer, and profile-use)
|
| 496 |
+
* - value profile runtime data structure suitable to be used by C
|
| 497 |
+
* runtime library.
|
| 498 |
+
*
|
| 499 |
+
* Both sources of data need to serialize to disk/memory-buffer in common
|
| 500 |
+
* format: ValueProfData. The abstraction allows compiler-rt's raw profiler
|
| 501 |
+
* writer to share the same format and code with indexed profile writer.
|
| 502 |
+
*
|
| 503 |
+
* For documentation of the member methods below, refer to corresponding methods
|
| 504 |
+
* in class InstrProfRecord.
|
| 505 |
+
*/
|
| 506 |
+
typedef struct ValueProfRecordClosure {
|
| 507 |
+
const void *Record;
|
| 508 |
+
uint32_t (*GetNumValueKinds)(const void *Record);
|
| 509 |
+
uint32_t (*GetNumValueSites)(const void *Record, uint32_t VKind);
|
| 510 |
+
uint32_t (*GetNumValueData)(const void *Record, uint32_t VKind);
|
| 511 |
+
uint32_t (*GetNumValueDataForSite)(const void *R, uint32_t VK, uint32_t S);
|
| 512 |
+
|
| 513 |
+
/*
|
| 514 |
+
* After extracting the value profile data from the value profile record,
|
| 515 |
+
* this method is used to map the in-memory value to on-disk value. If
|
| 516 |
+
* the method is null, value will be written out untranslated.
|
| 517 |
+
*/
|
| 518 |
+
uint64_t (*RemapValueData)(uint32_t, uint64_t Value);
|
| 519 |
+
void (*GetValueForSite)(const void *R, InstrProfValueData *Dst, uint32_t K,
|
| 520 |
+
uint32_t S);
|
| 521 |
+
ValueProfData *(*AllocValueProfData)(size_t TotalSizeInBytes);
|
| 522 |
+
} ValueProfRecordClosure;
|
| 523 |
+
|
| 524 |
+
INSTR_PROF_VISIBILITY ValueProfRecord *
|
| 525 |
+
getFirstValueProfRecord(ValueProfData *VPD);
|
| 526 |
+
INSTR_PROF_VISIBILITY ValueProfRecord *
|
| 527 |
+
getValueProfRecordNext(ValueProfRecord *VPR);
|
| 528 |
+
INSTR_PROF_VISIBILITY InstrProfValueData *
|
| 529 |
+
getValueProfRecordValueData(ValueProfRecord *VPR);
|
| 530 |
+
INSTR_PROF_VISIBILITY uint32_t
|
| 531 |
+
getValueProfRecordHeaderSize(uint32_t NumValueSites);
|
| 532 |
+
|
| 533 |
+
#undef INSTR_PROF_VALUE_PROF_DATA
|
| 534 |
+
#endif /* INSTR_PROF_VALUE_PROF_DATA */
|
| 535 |
+
|
| 536 |
+
|
| 537 |
+
#ifdef INSTR_PROF_COMMON_API_IMPL
|
| 538 |
+
#define INSTR_PROF_DATA_DEFINED
|
| 539 |
+
#ifdef __cplusplus
|
| 540 |
+
#define INSTR_PROF_INLINE inline
|
| 541 |
+
#define INSTR_PROF_NULLPTR nullptr
|
| 542 |
+
#else
|
| 543 |
+
#define INSTR_PROF_INLINE
|
| 544 |
+
#define INSTR_PROF_NULLPTR NULL
|
| 545 |
+
#endif
|
| 546 |
+
|
| 547 |
+
#ifndef offsetof
|
| 548 |
+
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
| 549 |
+
#endif
|
| 550 |
+
|
| 551 |
+
// clang-format on
|
| 552 |
+
|
| 553 |
+
/*!
|
| 554 |
+
* Return the \c ValueProfRecord header size including the
|
| 555 |
+
* padding bytes.
|
| 556 |
+
*/
|
| 557 |
+
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE uint32_t
|
| 558 |
+
getValueProfRecordHeaderSize(uint32_t NumValueSites) {
|
| 559 |
+
uint32_t Size = offsetof(ValueProfRecord, SiteCountArray) +
|
| 560 |
+
sizeof(uint8_t) * NumValueSites;
|
| 561 |
+
/* Round the size to multiple of 8 bytes. */
|
| 562 |
+
Size = (Size + 7) & ~7;
|
| 563 |
+
return Size;
|
| 564 |
+
}
|
| 565 |
+
|
| 566 |
+
/*!
|
| 567 |
+
* Return the total size of the value profile record including the
|
| 568 |
+
* header and the value data.
|
| 569 |
+
*/
|
| 570 |
+
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE uint32_t
|
| 571 |
+
getValueProfRecordSize(uint32_t NumValueSites, uint32_t NumValueData) {
|
| 572 |
+
return getValueProfRecordHeaderSize(NumValueSites) +
|
| 573 |
+
sizeof(InstrProfValueData) * NumValueData;
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
/*!
|
| 577 |
+
* Return the pointer to the start of value data array.
|
| 578 |
+
*/
|
| 579 |
+
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE InstrProfValueData *
|
| 580 |
+
getValueProfRecordValueData(ValueProfRecord *This) {
|
| 581 |
+
return (InstrProfValueData *)((char *)This + getValueProfRecordHeaderSize(
|
| 582 |
+
This->NumValueSites));
|
| 583 |
+
}
|
| 584 |
+
|
| 585 |
+
/*!
|
| 586 |
+
* Return the total number of value data for \c This record.
|
| 587 |
+
*/
|
| 588 |
+
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE uint32_t
|
| 589 |
+
getValueProfRecordNumValueData(ValueProfRecord *This) {
|
| 590 |
+
uint32_t NumValueData = 0;
|
| 591 |
+
uint32_t I;
|
| 592 |
+
for (I = 0; I < This->NumValueSites; I++)
|
| 593 |
+
NumValueData += This->SiteCountArray[I];
|
| 594 |
+
return NumValueData;
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
/*!
|
| 598 |
+
* Use this method to advance to the next \c This \c ValueProfRecord.
|
| 599 |
+
*/
|
| 600 |
+
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE ValueProfRecord *
|
| 601 |
+
getValueProfRecordNext(ValueProfRecord *This) {
|
| 602 |
+
uint32_t NumValueData = getValueProfRecordNumValueData(This);
|
| 603 |
+
return (ValueProfRecord *)((char *)This +
|
| 604 |
+
getValueProfRecordSize(This->NumValueSites,
|
| 605 |
+
NumValueData));
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
/*!
|
| 609 |
+
* Return the first \c ValueProfRecord instance.
|
| 610 |
+
*/
|
| 611 |
+
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE ValueProfRecord *
|
| 612 |
+
getFirstValueProfRecord(ValueProfData *This) {
|
| 613 |
+
return (ValueProfRecord *)((char *)This + sizeof(ValueProfData));
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
/* Closure based interfaces. */
|
| 617 |
+
|
| 618 |
+
/*!
|
| 619 |
+
* Return the total size in bytes of the on-disk value profile data
|
| 620 |
+
* given the data stored in Record.
|
| 621 |
+
*/
|
| 622 |
+
INSTR_PROF_VISIBILITY uint32_t
|
| 623 |
+
getValueProfDataSize(ValueProfRecordClosure *Closure) {
|
| 624 |
+
uint32_t Kind;
|
| 625 |
+
uint32_t TotalSize = sizeof(ValueProfData);
|
| 626 |
+
const void *Record = Closure->Record;
|
| 627 |
+
|
| 628 |
+
for (Kind = IPVK_First; Kind <= IPVK_Last; Kind++) {
|
| 629 |
+
uint32_t NumValueSites = Closure->GetNumValueSites(Record, Kind);
|
| 630 |
+
if (!NumValueSites)
|
| 631 |
+
continue;
|
| 632 |
+
TotalSize += getValueProfRecordSize(NumValueSites,
|
| 633 |
+
Closure->GetNumValueData(Record, Kind));
|
| 634 |
+
}
|
| 635 |
+
return TotalSize;
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
/*!
|
| 639 |
+
* Extract value profile data of a function for the profile kind \c ValueKind
|
| 640 |
+
* from the \c Closure and serialize the data into \c This record instance.
|
| 641 |
+
*/
|
| 642 |
+
INSTR_PROF_VISIBILITY void
|
| 643 |
+
serializeValueProfRecordFrom(ValueProfRecord *This,
|
| 644 |
+
ValueProfRecordClosure *Closure,
|
| 645 |
+
uint32_t ValueKind, uint32_t NumValueSites) {
|
| 646 |
+
uint32_t S;
|
| 647 |
+
const void *Record = Closure->Record;
|
| 648 |
+
This->Kind = ValueKind;
|
| 649 |
+
This->NumValueSites = NumValueSites;
|
| 650 |
+
InstrProfValueData *DstVD = getValueProfRecordValueData(This);
|
| 651 |
+
|
| 652 |
+
for (S = 0; S < NumValueSites; S++) {
|
| 653 |
+
uint32_t ND = Closure->GetNumValueDataForSite(Record, ValueKind, S);
|
| 654 |
+
This->SiteCountArray[S] = ND;
|
| 655 |
+
Closure->GetValueForSite(Record, DstVD, ValueKind, S);
|
| 656 |
+
DstVD += ND;
|
| 657 |
+
}
|
| 658 |
+
}
|
| 659 |
+
|
| 660 |
+
/*!
|
| 661 |
+
* Extract value profile data of a function from the \c Closure
|
| 662 |
+
* and serialize the data into \c DstData if it is not NULL or heap
|
| 663 |
+
* memory allocated by the \c Closure's allocator method. If \c
|
| 664 |
+
* DstData is not null, the caller is expected to set the TotalSize
|
| 665 |
+
* in DstData.
|
| 666 |
+
*/
|
| 667 |
+
INSTR_PROF_VISIBILITY ValueProfData *
|
| 668 |
+
serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
|
| 669 |
+
ValueProfData *DstData) {
|
| 670 |
+
uint32_t Kind;
|
| 671 |
+
uint32_t TotalSize =
|
| 672 |
+
DstData ? DstData->TotalSize : getValueProfDataSize(Closure);
|
| 673 |
+
|
| 674 |
+
ValueProfData *VPD =
|
| 675 |
+
DstData ? DstData : Closure->AllocValueProfData(TotalSize);
|
| 676 |
+
|
| 677 |
+
VPD->TotalSize = TotalSize;
|
| 678 |
+
VPD->NumValueKinds = Closure->GetNumValueKinds(Closure->Record);
|
| 679 |
+
ValueProfRecord *VR = getFirstValueProfRecord(VPD);
|
| 680 |
+
for (Kind = IPVK_First; Kind <= IPVK_Last; Kind++) {
|
| 681 |
+
uint32_t NumValueSites = Closure->GetNumValueSites(Closure->Record, Kind);
|
| 682 |
+
if (!NumValueSites)
|
| 683 |
+
continue;
|
| 684 |
+
serializeValueProfRecordFrom(VR, Closure, Kind, NumValueSites);
|
| 685 |
+
VR = getValueProfRecordNext(VR);
|
| 686 |
+
}
|
| 687 |
+
return VPD;
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
#undef INSTR_PROF_COMMON_API_IMPL
|
| 691 |
+
#endif /* INSTR_PROF_COMMON_API_IMPL */
|
| 692 |
+
|
| 693 |
+
/*============================================================================*/
|
| 694 |
+
|
| 695 |
+
// clang-format off:consider re-enabling clang-format if auto-formatted C macros
|
| 696 |
+
// are readable (e.g., after `issue #82426` is fixed)
|
| 697 |
+
#ifndef INSTR_PROF_DATA_DEFINED
|
| 698 |
+
|
| 699 |
+
#ifndef INSTR_PROF_DATA_INC
|
| 700 |
+
#define INSTR_PROF_DATA_INC
|
| 701 |
+
|
| 702 |
+
/* Helper macros. */
|
| 703 |
+
#define INSTR_PROF_SIMPLE_QUOTE(x) #x
|
| 704 |
+
#define INSTR_PROF_QUOTE(x) INSTR_PROF_SIMPLE_QUOTE(x)
|
| 705 |
+
#define INSTR_PROF_SIMPLE_CONCAT(x,y) x ## y
|
| 706 |
+
#define INSTR_PROF_CONCAT(x,y) INSTR_PROF_SIMPLE_CONCAT(x,y)
|
| 707 |
+
|
| 708 |
+
/* Magic number to detect file format and endianness.
|
| 709 |
+
* Use 255 at one end, since no UTF-8 file can use that character. Avoid 0,
|
| 710 |
+
* so that utilities, like strings, don't grab it as a string. 129 is also
|
| 711 |
+
* invalid UTF-8, and high enough to be interesting.
|
| 712 |
+
* Use "lprofr" in the centre to stand for "LLVM Profile Raw", or "lprofR"
|
| 713 |
+
* for 32-bit platforms.
|
| 714 |
+
*/
|
| 715 |
+
#define INSTR_PROF_RAW_MAGIC_64 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
|
| 716 |
+
(uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \
|
| 717 |
+
(uint64_t)'f' << 16 | (uint64_t)'r' << 8 | (uint64_t)129
|
| 718 |
+
#define INSTR_PROF_RAW_MAGIC_32 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
|
| 719 |
+
(uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \
|
| 720 |
+
(uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129
|
| 721 |
+
|
| 722 |
+
/* Raw profile format version (start from 1). */
|
| 723 |
+
#define INSTR_PROF_RAW_VERSION 10
|
| 724 |
+
/* Indexed profile format version (start from 1). */
|
| 725 |
+
#define INSTR_PROF_INDEX_VERSION 12
|
| 726 |
+
/* Coverage mapping format version (start from 0). */
|
| 727 |
+
#define INSTR_PROF_COVMAP_VERSION 6
|
| 728 |
+
|
| 729 |
+
/* Profile version is always of type uint64_t. Reserve the upper 32 bits in the
|
| 730 |
+
* version for other variants of profile. We set the 8th most significant bit
|
| 731 |
+
* (i.e. bit 56) to 1 to indicate if this is an IR-level instrumentation
|
| 732 |
+
* generated profile, and 0 if this is a Clang FE generated profile.
|
| 733 |
+
* 1 in bit 57 indicates there are context-sensitive records in the profile.
|
| 734 |
+
* The 54th bit indicates whether to always instrument loop entry blocks.
|
| 735 |
+
* The 58th bit indicates whether to always instrument function entry blocks.
|
| 736 |
+
* The 59th bit indicates whether to use debug info to correlate profiles.
|
| 737 |
+
* The 60th bit indicates single byte coverage instrumentation.
|
| 738 |
+
* The 61st bit indicates function entry instrumentation only.
|
| 739 |
+
* The 62nd bit indicates whether memory profile information is present.
|
| 740 |
+
* The 63rd bit indicates if this is a temporal profile.
|
| 741 |
+
*/
|
| 742 |
+
#define VARIANT_MASKS_ALL 0xffffffff00000000ULL
|
| 743 |
+
#define GET_VERSION(V) ((V) & ~VARIANT_MASKS_ALL)
|
| 744 |
+
#define VARIANT_MASK_INSTR_LOOP_ENTRIES (0x1ULL << 55)
|
| 745 |
+
#define VARIANT_MASK_IR_PROF (0x1ULL << 56)
|
| 746 |
+
#define VARIANT_MASK_CSIR_PROF (0x1ULL << 57)
|
| 747 |
+
#define VARIANT_MASK_INSTR_ENTRY (0x1ULL << 58)
|
| 748 |
+
#define VARIANT_MASK_DBG_CORRELATE (0x1ULL << 59)
|
| 749 |
+
#define VARIANT_MASK_BYTE_COVERAGE (0x1ULL << 60)
|
| 750 |
+
#define VARIANT_MASK_FUNCTION_ENTRY_ONLY (0x1ULL << 61)
|
| 751 |
+
#define VARIANT_MASK_MEMPROF (0x1ULL << 62)
|
| 752 |
+
#define VARIANT_MASK_TEMPORAL_PROF (0x1ULL << 63)
|
| 753 |
+
#define INSTR_PROF_RAW_VERSION_VAR __llvm_profile_raw_version
|
| 754 |
+
#define INSTR_PROF_PROFILE_RUNTIME_VAR __llvm_profile_runtime
|
| 755 |
+
#define INSTR_PROF_PROFILE_COUNTER_BIAS_VAR __llvm_profile_counter_bias
|
| 756 |
+
#define INSTR_PROF_PROFILE_BITMAP_BIAS_VAR __llvm_profile_bitmap_bias
|
| 757 |
+
#define INSTR_PROF_PROFILE_SET_TIMESTAMP __llvm_profile_set_timestamp
|
| 758 |
+
#define INSTR_PROF_PROFILE_SAMPLING_VAR __llvm_profile_sampling
|
| 759 |
+
|
| 760 |
+
/* The variable that holds the name of the profile data
|
| 761 |
+
* specified via command line. */
|
| 762 |
+
#define INSTR_PROF_PROFILE_NAME_VAR __llvm_profile_filename
|
| 763 |
+
|
| 764 |
+
/* section name strings common to all targets other
|
| 765 |
+
than WIN32 */
|
| 766 |
+
#define INSTR_PROF_DATA_COMMON __llvm_prf_data
|
| 767 |
+
#define INSTR_PROF_NAME_COMMON __llvm_prf_names
|
| 768 |
+
#define INSTR_PROF_VNAME_COMMON __llvm_prf_vns
|
| 769 |
+
#define INSTR_PROF_CNTS_COMMON __llvm_prf_cnts
|
| 770 |
+
#define INSTR_PROF_BITS_COMMON __llvm_prf_bits
|
| 771 |
+
#define INSTR_PROF_VALS_COMMON __llvm_prf_vals
|
| 772 |
+
#define INSTR_PROF_VNODES_COMMON __llvm_prf_vnds
|
| 773 |
+
#define INSTR_PROF_VTAB_COMMON __llvm_prf_vtab
|
| 774 |
+
#define INSTR_PROF_COVMAP_COMMON __llvm_covmap
|
| 775 |
+
#define INSTR_PROF_COVFUN_COMMON __llvm_covfun
|
| 776 |
+
#define INSTR_PROF_COVDATA_COMMON __llvm_covdata
|
| 777 |
+
#define INSTR_PROF_COVNAME_COMMON __llvm_covnames
|
| 778 |
+
#define INSTR_PROF_COVINIT_COMMON __llvm_covinit
|
| 779 |
+
|
| 780 |
+
/* Windows section names. Because these section names contain dollar characters,
|
| 781 |
+
* they must be quoted.
|
| 782 |
+
*/
|
| 783 |
+
#define INSTR_PROF_DATA_COFF ".lprfd$M"
|
| 784 |
+
#define INSTR_PROF_NAME_COFF ".lprfn$M"
|
| 785 |
+
#define INSTR_PROF_VNAME_COFF ".lprfvn$M"
|
| 786 |
+
#define INSTR_PROF_CNTS_COFF ".lprfc$M"
|
| 787 |
+
#define INSTR_PROF_BITS_COFF ".lprfb$M"
|
| 788 |
+
#define INSTR_PROF_VALS_COFF ".lprfv$M"
|
| 789 |
+
#define INSTR_PROF_VNODES_COFF ".lprfnd$M"
|
| 790 |
+
#define INSTR_PROF_VTAB_COFF ".lprfvt$M"
|
| 791 |
+
#define INSTR_PROF_COVMAP_COFF ".lcovmap$M"
|
| 792 |
+
#define INSTR_PROF_COVFUN_COFF ".lcovfun$M"
|
| 793 |
+
/* Since cov data and cov names sections are not allocated, we don't need to
|
| 794 |
+
* access them at runtime.
|
| 795 |
+
*/
|
| 796 |
+
#define INSTR_PROF_COVDATA_COFF ".lcovd"
|
| 797 |
+
#define INSTR_PROF_COVNAME_COFF ".lcovn"
|
| 798 |
+
|
| 799 |
+
// FIXME: Placeholder for Windows. Windows currently does not initialize
|
| 800 |
+
// the GCOV functions in the runtime.
|
| 801 |
+
#define INSTR_PROF_COVINIT_COFF ".lcovd$M"
|
| 802 |
+
|
| 803 |
+
#ifdef _WIN32
|
| 804 |
+
/* Runtime section names and name strings. */
|
| 805 |
+
#define INSTR_PROF_DATA_SECT_NAME INSTR_PROF_DATA_COFF
|
| 806 |
+
#define INSTR_PROF_NAME_SECT_NAME INSTR_PROF_NAME_COFF
|
| 807 |
+
#define INSTR_PROF_CNTS_SECT_NAME INSTR_PROF_CNTS_COFF
|
| 808 |
+
#define INSTR_PROF_BITS_SECT_NAME INSTR_PROF_BITS_COFF
|
| 809 |
+
#define INSTR_PROF_VTAB_SECT_NAME INSTR_PROF_VTAB_COFF
|
| 810 |
+
#define INSTR_PROF_VNAME_SECT_NAME INSTR_PROF_VNAME_COFF
|
| 811 |
+
/* Array of pointers. Each pointer points to a list
|
| 812 |
+
* of value nodes associated with one value site.
|
| 813 |
+
*/
|
| 814 |
+
#define INSTR_PROF_VALS_SECT_NAME INSTR_PROF_VALS_COFF
|
| 815 |
+
/* Value profile nodes section. */
|
| 816 |
+
#define INSTR_PROF_VNODES_SECT_NAME INSTR_PROF_VNODES_COFF
|
| 817 |
+
#define INSTR_PROF_COVMAP_SECT_NAME INSTR_PROF_COVMAP_COFF
|
| 818 |
+
#define INSTR_PROF_COVFUN_SECT_NAME INSTR_PROF_COVFUN_COFF
|
| 819 |
+
#define INSTR_PROF_COVDATA_SECT_NAME INSTR_PROF_COVDATA_COFF
|
| 820 |
+
#define INSTR_PROF_COVNAME_SECT_NAME INSTR_PROF_COVNAME_COFF
|
| 821 |
+
#define INSTR_PROF_COVINIT_SECT_NAME INSTR_PROF_COVINIT_COFF
|
| 822 |
+
#else
|
| 823 |
+
/* Runtime section names and name strings. */
|
| 824 |
+
#define INSTR_PROF_DATA_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_DATA_COMMON)
|
| 825 |
+
#define INSTR_PROF_NAME_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_NAME_COMMON)
|
| 826 |
+
#define INSTR_PROF_CNTS_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_CNTS_COMMON)
|
| 827 |
+
#define INSTR_PROF_BITS_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_BITS_COMMON)
|
| 828 |
+
#define INSTR_PROF_VTAB_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_VTAB_COMMON)
|
| 829 |
+
#define INSTR_PROF_VNAME_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_VNAME_COMMON)
|
| 830 |
+
/* Array of pointers. Each pointer points to a list
|
| 831 |
+
* of value nodes associated with one value site.
|
| 832 |
+
*/
|
| 833 |
+
#define INSTR_PROF_VALS_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_VALS_COMMON)
|
| 834 |
+
/* Value profile nodes section. */
|
| 835 |
+
#define INSTR_PROF_VNODES_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COMMON)
|
| 836 |
+
#define INSTR_PROF_COVMAP_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_COMMON)
|
| 837 |
+
#define INSTR_PROF_COVFUN_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVFUN_COMMON)
|
| 838 |
+
#define INSTR_PROF_COVDATA_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVDATA_COMMON)
|
| 839 |
+
#define INSTR_PROF_COVNAME_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVNAME_COMMON)
|
| 840 |
+
#define INSTR_PROF_COVINIT_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVINIT_COMMON)
|
| 841 |
+
#endif
|
| 842 |
+
|
| 843 |
+
/* Macros to define start/stop section symbol for a given
|
| 844 |
+
* section on Linux. For instance
|
| 845 |
+
* INSTR_PROF_SECT_START(INSTR_PROF_DATA_SECT_NAME) will
|
| 846 |
+
* expand to __start___llvm_prof_data
|
| 847 |
+
*/
|
| 848 |
+
#define INSTR_PROF_SECT_START(Sect) \
|
| 849 |
+
INSTR_PROF_CONCAT(__start_,Sect)
|
| 850 |
+
#define INSTR_PROF_SECT_STOP(Sect) \
|
| 851 |
+
INSTR_PROF_CONCAT(__stop_,Sect)
|
| 852 |
+
|
| 853 |
+
/* Value Profiling API linkage name. */
|
| 854 |
+
#define INSTR_PROF_VALUE_PROF_FUNC __llvm_profile_instrument_target
|
| 855 |
+
#define INSTR_PROF_VALUE_PROF_FUNC_STR \
|
| 856 |
+
INSTR_PROF_QUOTE(INSTR_PROF_VALUE_PROF_FUNC)
|
| 857 |
+
#define INSTR_PROF_VALUE_PROF_MEMOP_FUNC __llvm_profile_instrument_memop
|
| 858 |
+
#define INSTR_PROF_VALUE_PROF_MEMOP_FUNC_STR \
|
| 859 |
+
INSTR_PROF_QUOTE(INSTR_PROF_VALUE_PROF_MEMOP_FUNC)
|
| 860 |
+
|
| 861 |
+
/* InstrProfile per-function control data alignment. */
|
| 862 |
+
#define INSTR_PROF_DATA_ALIGNMENT 8
|
| 863 |
+
|
| 864 |
+
/* The data structure that represents a tracked value by the
|
| 865 |
+
* value profiler.
|
| 866 |
+
*/
|
| 867 |
+
typedef struct InstrProfValueData {
|
| 868 |
+
/* Profiled value. */
|
| 869 |
+
uint64_t Value;
|
| 870 |
+
/* Number of times the value appears in the training run. */
|
| 871 |
+
uint64_t Count;
|
| 872 |
+
} InstrProfValueData;
|
| 873 |
+
|
| 874 |
+
#endif /* INSTR_PROF_DATA_INC */
|
| 875 |
+
|
| 876 |
+
#else
|
| 877 |
+
#undef INSTR_PROF_DATA_DEFINED
|
| 878 |
+
#endif
|
| 879 |
+
|
| 880 |
+
#undef COVMAP_V2_OR_V3
|
| 881 |
+
|
| 882 |
+
#ifdef INSTR_PROF_VALUE_PROF_MEMOP_API
|
| 883 |
+
|
| 884 |
+
#ifdef __cplusplus
|
| 885 |
+
#define INSTR_PROF_INLINE inline
|
| 886 |
+
#else
|
| 887 |
+
#define INSTR_PROF_INLINE
|
| 888 |
+
#endif
|
| 889 |
+
|
| 890 |
+
/* The value range buckets (22 buckets) for the memop size value profiling looks
|
| 891 |
+
* like:
|
| 892 |
+
*
|
| 893 |
+
* [0, 0]
|
| 894 |
+
* [1, 1]
|
| 895 |
+
* [2, 2]
|
| 896 |
+
* [3, 3]
|
| 897 |
+
* [4, 4]
|
| 898 |
+
* [5, 5]
|
| 899 |
+
* [6, 6]
|
| 900 |
+
* [7, 7]
|
| 901 |
+
* [8, 8]
|
| 902 |
+
* [9, 15]
|
| 903 |
+
* [16, 16]
|
| 904 |
+
* [17, 31]
|
| 905 |
+
* [32, 32]
|
| 906 |
+
* [33, 63]
|
| 907 |
+
* [64, 64]
|
| 908 |
+
* [65, 127]
|
| 909 |
+
* [128, 128]
|
| 910 |
+
* [129, 255]
|
| 911 |
+
* [256, 256]
|
| 912 |
+
* [257, 511]
|
| 913 |
+
* [512, 512]
|
| 914 |
+
* [513, UINT64_MAX]
|
| 915 |
+
*
|
| 916 |
+
* Each range has a 'representative value' which is the lower end value of the
|
| 917 |
+
* range and used to store in the runtime profile data records and the VP
|
| 918 |
+
* metadata. For example, it's 2 for [2, 2] and 64 for [65, 127].
|
| 919 |
+
*/
|
| 920 |
+
#define INSTR_PROF_NUM_BUCKETS 22
|
| 921 |
+
|
| 922 |
+
/*
|
| 923 |
+
* Clz and Popcount. This code was copied from
|
| 924 |
+
* compiler-rt/lib/fuzzer/{FuzzerBuiltins.h,FuzzerBuiltinsMsvc.h} and
|
| 925 |
+
* llvm/include/llvm/Support/MathExtras.h.
|
| 926 |
+
*/
|
| 927 |
+
#if defined(_MSC_VER) && !defined(__clang__)
|
| 928 |
+
|
| 929 |
+
#include <intrin.h>
|
| 930 |
+
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
|
| 931 |
+
int InstProfClzll(unsigned long long X) {
|
| 932 |
+
unsigned long LeadZeroIdx = 0;
|
| 933 |
+
#if !defined(_M_ARM64) && !defined(_M_X64)
|
| 934 |
+
// Scan the high 32 bits.
|
| 935 |
+
if (_BitScanReverse(&LeadZeroIdx, (unsigned long)(X >> 32)))
|
| 936 |
+
return (int)(63 - (LeadZeroIdx + 32)); // Create a bit offset
|
| 937 |
+
// from the MSB.
|
| 938 |
+
// Scan the low 32 bits.
|
| 939 |
+
if (_BitScanReverse(&LeadZeroIdx, (unsigned long)(X)))
|
| 940 |
+
return (int)(63 - LeadZeroIdx);
|
| 941 |
+
#else
|
| 942 |
+
if (_BitScanReverse64(&LeadZeroIdx, X)) return 63 - LeadZeroIdx;
|
| 943 |
+
#endif
|
| 944 |
+
return 64;
|
| 945 |
+
}
|
| 946 |
+
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
|
| 947 |
+
int InstProfPopcountll(unsigned long long X) {
|
| 948 |
+
// This code originates from https://reviews.llvm.org/rG30626254510f.
|
| 949 |
+
unsigned long long v = X;
|
| 950 |
+
v = v - ((v >> 1) & 0x5555555555555555ULL);
|
| 951 |
+
v = (v & 0x3333333333333333ULL) + ((v >> 2) & 0x3333333333333333ULL);
|
| 952 |
+
v = (v + (v >> 4)) & 0x0F0F0F0F0F0F0F0FULL;
|
| 953 |
+
return (int)((unsigned long long)(v * 0x0101010101010101ULL) >> 56);
|
| 954 |
+
}
|
| 955 |
+
|
| 956 |
+
#else
|
| 957 |
+
|
| 958 |
+
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
|
| 959 |
+
int InstProfClzll(unsigned long long X) { return __builtin_clzll(X); }
|
| 960 |
+
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE
|
| 961 |
+
int InstProfPopcountll(unsigned long long X) { return __builtin_popcountll(X); }
|
| 962 |
+
|
| 963 |
+
#endif /* defined(_MSC_VER) && !defined(__clang__) */
|
| 964 |
+
|
| 965 |
+
// clang-format on
|
| 966 |
+
|
| 967 |
+
/* Map an (observed) memop size value to the representative value of its range.
|
| 968 |
+
* For example, 5 -> 5, 22 -> 17, 99 -> 65, 256 -> 256, 1001 -> 513. */
|
| 969 |
+
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE uint64_t
|
| 970 |
+
InstrProfGetRangeRepValue(uint64_t Value) {
|
| 971 |
+
if (Value <= 8)
|
| 972 |
+
// The first ranges are individually tracked. Use the value as is.
|
| 973 |
+
return Value;
|
| 974 |
+
else if (Value >= 513)
|
| 975 |
+
// The last range is mapped to its lowest value.
|
| 976 |
+
return 513;
|
| 977 |
+
else if (InstProfPopcountll(Value) == 1)
|
| 978 |
+
// If it's a power of two, use it as is.
|
| 979 |
+
return Value;
|
| 980 |
+
else
|
| 981 |
+
// Otherwise, take to the previous power of two + 1.
|
| 982 |
+
return (UINT64_C(1) << (64 - InstProfClzll(Value) - 1)) + 1;
|
| 983 |
+
}
|
| 984 |
+
|
| 985 |
+
/* Return true if the range that an (observed) memop size value belongs to has
|
| 986 |
+
* only a single value in the range. For example, 0 -> true, 8 -> true, 10 ->
|
| 987 |
+
* false, 64 -> true, 100 -> false, 513 -> false. */
|
| 988 |
+
INSTR_PROF_VISIBILITY INSTR_PROF_INLINE unsigned
|
| 989 |
+
InstrProfIsSingleValRange(uint64_t Value) {
|
| 990 |
+
if (Value <= 8)
|
| 991 |
+
// The first ranges are individually tracked.
|
| 992 |
+
return 1;
|
| 993 |
+
else if (InstProfPopcountll(Value) == 1)
|
| 994 |
+
// If it's a power of two, there's only one value.
|
| 995 |
+
return 1;
|
| 996 |
+
else
|
| 997 |
+
// Otherwise, there's more than one value in the range.
|
| 998 |
+
return 0;
|
| 999 |
+
}
|
| 1000 |
+
|
| 1001 |
+
#endif /* INSTR_PROF_VALUE_PROF_MEMOP_API */
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/InstrProfReader.h
ADDED
|
@@ -0,0 +1,906 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- InstrProfReader.h - Instrumented profiling readers -------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file contains support for reading profiling data for instrumentation
|
| 10 |
+
// based PGO and coverage.
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#ifndef LLVM_PROFILEDATA_INSTRPROFREADER_H
|
| 15 |
+
#define LLVM_PROFILEDATA_INSTRPROFREADER_H
|
| 16 |
+
|
| 17 |
+
#include "llvm/ADT/ArrayRef.h"
|
| 18 |
+
#include "llvm/ADT/StringRef.h"
|
| 19 |
+
#include "llvm/IR/ProfileSummary.h"
|
| 20 |
+
#include "llvm/Object/BuildID.h"
|
| 21 |
+
#include "llvm/ProfileData/DataAccessProf.h"
|
| 22 |
+
#include "llvm/ProfileData/InstrProf.h"
|
| 23 |
+
#include "llvm/ProfileData/InstrProfCorrelator.h"
|
| 24 |
+
#include "llvm/ProfileData/MemProf.h"
|
| 25 |
+
#include "llvm/ProfileData/MemProfSummary.h"
|
| 26 |
+
#include "llvm/ProfileData/MemProfYAML.h"
|
| 27 |
+
#include "llvm/Support/Endian.h"
|
| 28 |
+
#include "llvm/Support/Error.h"
|
| 29 |
+
#include "llvm/Support/LineIterator.h"
|
| 30 |
+
#include "llvm/Support/MathExtras.h"
|
| 31 |
+
#include "llvm/Support/MemoryBuffer.h"
|
| 32 |
+
#include "llvm/Support/OnDiskHashTable.h"
|
| 33 |
+
#include "llvm/Support/SwapByteOrder.h"
|
| 34 |
+
#include <algorithm>
|
| 35 |
+
#include <cassert>
|
| 36 |
+
#include <cstddef>
|
| 37 |
+
#include <cstdint>
|
| 38 |
+
#include <iterator>
|
| 39 |
+
#include <memory>
|
| 40 |
+
#include <utility>
|
| 41 |
+
#include <vector>
|
| 42 |
+
|
| 43 |
+
namespace llvm {
|
| 44 |
+
|
| 45 |
+
class InstrProfReader;
|
| 46 |
+
|
| 47 |
+
namespace vfs {
|
| 48 |
+
class FileSystem;
|
| 49 |
+
} // namespace vfs
|
| 50 |
+
|
| 51 |
+
/// A file format agnostic iterator over profiling data.
|
| 52 |
+
template <class record_type = NamedInstrProfRecord,
|
| 53 |
+
class reader_type = InstrProfReader>
|
| 54 |
+
class InstrProfIterator {
|
| 55 |
+
public:
|
| 56 |
+
using iterator_category = std::input_iterator_tag;
|
| 57 |
+
using value_type = record_type;
|
| 58 |
+
using difference_type = std::ptrdiff_t;
|
| 59 |
+
using pointer = value_type *;
|
| 60 |
+
using reference = value_type &;
|
| 61 |
+
|
| 62 |
+
private:
|
| 63 |
+
reader_type *Reader = nullptr;
|
| 64 |
+
value_type Record;
|
| 65 |
+
|
| 66 |
+
void increment() {
|
| 67 |
+
if (Error E = Reader->readNextRecord(Record)) {
|
| 68 |
+
// Handle errors in the reader.
|
| 69 |
+
InstrProfError::take(std::move(E));
|
| 70 |
+
*this = InstrProfIterator();
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
public:
|
| 75 |
+
InstrProfIterator() = default;
|
| 76 |
+
InstrProfIterator(reader_type *Reader) : Reader(Reader) { increment(); }
|
| 77 |
+
|
| 78 |
+
InstrProfIterator &operator++() {
|
| 79 |
+
increment();
|
| 80 |
+
return *this;
|
| 81 |
+
}
|
| 82 |
+
bool operator==(const InstrProfIterator &RHS) const {
|
| 83 |
+
return Reader == RHS.Reader;
|
| 84 |
+
}
|
| 85 |
+
bool operator!=(const InstrProfIterator &RHS) const {
|
| 86 |
+
return Reader != RHS.Reader;
|
| 87 |
+
}
|
| 88 |
+
value_type &operator*() { return Record; }
|
| 89 |
+
value_type *operator->() { return &Record; }
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
/// Base class and interface for reading profiling data of any known instrprof
|
| 93 |
+
/// format. Provides an iterator over NamedInstrProfRecords.
|
| 94 |
+
class InstrProfReader {
|
| 95 |
+
instrprof_error LastError = instrprof_error::success;
|
| 96 |
+
std::string LastErrorMsg;
|
| 97 |
+
|
| 98 |
+
public:
|
| 99 |
+
InstrProfReader() = default;
|
| 100 |
+
virtual ~InstrProfReader() = default;
|
| 101 |
+
|
| 102 |
+
/// Read the header. Required before reading first record.
|
| 103 |
+
virtual Error readHeader() = 0;
|
| 104 |
+
|
| 105 |
+
/// Read a single record.
|
| 106 |
+
virtual Error readNextRecord(NamedInstrProfRecord &Record) = 0;
|
| 107 |
+
|
| 108 |
+
/// Read a list of binary ids.
|
| 109 |
+
virtual Error readBinaryIds(std::vector<llvm::object::BuildID> &BinaryIds) {
|
| 110 |
+
return success();
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/// Print binary ids.
|
| 114 |
+
virtual Error printBinaryIds(raw_ostream &OS) { return success(); };
|
| 115 |
+
|
| 116 |
+
/// Iterator over profile data.
|
| 117 |
+
InstrProfIterator<> begin() { return InstrProfIterator<>(this); }
|
| 118 |
+
InstrProfIterator<> end() { return InstrProfIterator<>(); }
|
| 119 |
+
|
| 120 |
+
/// Return the profile version.
|
| 121 |
+
virtual uint64_t getVersion() const = 0;
|
| 122 |
+
|
| 123 |
+
virtual bool isIRLevelProfile() const = 0;
|
| 124 |
+
|
| 125 |
+
virtual bool hasCSIRLevelProfile() const = 0;
|
| 126 |
+
|
| 127 |
+
virtual bool instrEntryBBEnabled() const = 0;
|
| 128 |
+
|
| 129 |
+
/// Return true if the profile instruments all loop entries.
|
| 130 |
+
virtual bool instrLoopEntriesEnabled() const = 0;
|
| 131 |
+
|
| 132 |
+
/// Return true if the profile has single byte counters representing coverage.
|
| 133 |
+
virtual bool hasSingleByteCoverage() const = 0;
|
| 134 |
+
|
| 135 |
+
/// Return true if the profile only instruments function entries.
|
| 136 |
+
virtual bool functionEntryOnly() const = 0;
|
| 137 |
+
|
| 138 |
+
/// Return true if profile includes a memory profile.
|
| 139 |
+
virtual bool hasMemoryProfile() const = 0;
|
| 140 |
+
|
| 141 |
+
/// Return true if this has a temporal profile.
|
| 142 |
+
virtual bool hasTemporalProfile() const = 0;
|
| 143 |
+
|
| 144 |
+
/// Returns a BitsetEnum describing the attributes of the profile. To check
|
| 145 |
+
/// individual attributes prefer using the helpers above.
|
| 146 |
+
virtual InstrProfKind getProfileKind() const = 0;
|
| 147 |
+
|
| 148 |
+
/// Return the PGO symtab. There are three different readers:
|
| 149 |
+
/// Raw, Text, and Indexed profile readers. The first two types
|
| 150 |
+
/// of readers are used only by llvm-profdata tool, while the indexed
|
| 151 |
+
/// profile reader is also used by llvm-cov tool and the compiler (
|
| 152 |
+
/// backend or frontend). Since creating PGO symtab can create
|
| 153 |
+
/// significant runtime and memory overhead (as it touches data
|
| 154 |
+
/// for the whole program), InstrProfSymtab for the indexed profile
|
| 155 |
+
/// reader should be created on demand and it is recommended to be
|
| 156 |
+
/// only used for dumping purpose with llvm-proftool, not with the
|
| 157 |
+
/// compiler.
|
| 158 |
+
virtual InstrProfSymtab &getSymtab() = 0;
|
| 159 |
+
|
| 160 |
+
/// Compute the sum of counts and return in Sum.
|
| 161 |
+
void accumulateCounts(CountSumOrPercent &Sum, bool IsCS);
|
| 162 |
+
|
| 163 |
+
protected:
|
| 164 |
+
std::unique_ptr<InstrProfSymtab> Symtab;
|
| 165 |
+
/// A list of temporal profile traces.
|
| 166 |
+
SmallVector<TemporalProfTraceTy> TemporalProfTraces;
|
| 167 |
+
/// The total number of temporal profile traces seen.
|
| 168 |
+
uint64_t TemporalProfTraceStreamSize = 0;
|
| 169 |
+
|
| 170 |
+
/// Set the current error and return same.
|
| 171 |
+
Error error(instrprof_error Err, const std::string &ErrMsg = "") {
|
| 172 |
+
LastError = Err;
|
| 173 |
+
LastErrorMsg = ErrMsg;
|
| 174 |
+
if (Err == instrprof_error::success)
|
| 175 |
+
return Error::success();
|
| 176 |
+
return make_error<InstrProfError>(Err, ErrMsg);
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
Error error(Error &&E) {
|
| 180 |
+
handleAllErrors(std::move(E), [&](const InstrProfError &IPE) {
|
| 181 |
+
LastError = IPE.get();
|
| 182 |
+
LastErrorMsg = IPE.getMessage();
|
| 183 |
+
});
|
| 184 |
+
return make_error<InstrProfError>(LastError, LastErrorMsg);
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
/// Clear the current error and return a successful one.
|
| 188 |
+
Error success() { return error(instrprof_error::success); }
|
| 189 |
+
|
| 190 |
+
public:
|
| 191 |
+
/// Return true if the reader has finished reading the profile data.
|
| 192 |
+
bool isEOF() { return LastError == instrprof_error::eof; }
|
| 193 |
+
|
| 194 |
+
/// Return true if the reader encountered an error reading profiling data.
|
| 195 |
+
bool hasError() { return LastError != instrprof_error::success && !isEOF(); }
|
| 196 |
+
|
| 197 |
+
/// Get the current error.
|
| 198 |
+
Error getError() {
|
| 199 |
+
if (hasError())
|
| 200 |
+
return make_error<InstrProfError>(LastError, LastErrorMsg);
|
| 201 |
+
return Error::success();
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
/// Factory method to create an appropriately typed reader for the given
|
| 205 |
+
/// instrprof file.
|
| 206 |
+
static Expected<std::unique_ptr<InstrProfReader>> create(
|
| 207 |
+
const Twine &Path, vfs::FileSystem &FS,
|
| 208 |
+
const InstrProfCorrelator *Correlator = nullptr,
|
| 209 |
+
const object::BuildIDFetcher *BIDFetcher = nullptr,
|
| 210 |
+
const InstrProfCorrelator::ProfCorrelatorKind BIDFetcherCorrelatorKind =
|
| 211 |
+
InstrProfCorrelator::ProfCorrelatorKind::NONE,
|
| 212 |
+
std::function<void(Error)> Warn = nullptr);
|
| 213 |
+
|
| 214 |
+
static Expected<std::unique_ptr<InstrProfReader>> create(
|
| 215 |
+
std::unique_ptr<MemoryBuffer> Buffer,
|
| 216 |
+
const InstrProfCorrelator *Correlator = nullptr,
|
| 217 |
+
const object::BuildIDFetcher *BIDFetcher = nullptr,
|
| 218 |
+
const InstrProfCorrelator::ProfCorrelatorKind BIDFetcherCorrelatorKind =
|
| 219 |
+
InstrProfCorrelator::ProfCorrelatorKind::NONE,
|
| 220 |
+
std::function<void(Error)> Warn = nullptr);
|
| 221 |
+
|
| 222 |
+
/// \param Weight for raw profiles use this as the temporal profile trace
|
| 223 |
+
/// weight
|
| 224 |
+
/// \returns a list of temporal profile traces.
|
| 225 |
+
virtual SmallVector<TemporalProfTraceTy> &
|
| 226 |
+
getTemporalProfTraces(std::optional<uint64_t> Weight = {}) {
|
| 227 |
+
// For non-raw profiles we ignore the input weight and instead use the
|
| 228 |
+
// weights already in the traces.
|
| 229 |
+
return TemporalProfTraces;
|
| 230 |
+
}
|
| 231 |
+
/// \returns the total number of temporal profile traces seen.
|
| 232 |
+
uint64_t getTemporalProfTraceStreamSize() {
|
| 233 |
+
return TemporalProfTraceStreamSize;
|
| 234 |
+
}
|
| 235 |
+
};
|
| 236 |
+
|
| 237 |
+
/// Reader for the simple text based instrprof format.
|
| 238 |
+
///
|
| 239 |
+
/// This format is a simple text format that's suitable for test data. Records
|
| 240 |
+
/// are separated by one or more blank lines, and record fields are separated by
|
| 241 |
+
/// new lines.
|
| 242 |
+
///
|
| 243 |
+
/// Each record consists of a function name, a function hash, a number of
|
| 244 |
+
/// counters, and then each counter value, in that order.
|
| 245 |
+
class TextInstrProfReader : public InstrProfReader {
|
| 246 |
+
private:
|
| 247 |
+
/// The profile data file contents.
|
| 248 |
+
std::unique_ptr<MemoryBuffer> DataBuffer;
|
| 249 |
+
/// Iterator over the profile data.
|
| 250 |
+
line_iterator Line;
|
| 251 |
+
/// The attributes of the current profile.
|
| 252 |
+
InstrProfKind ProfileKind = InstrProfKind::Unknown;
|
| 253 |
+
|
| 254 |
+
Error readValueProfileData(InstrProfRecord &Record);
|
| 255 |
+
|
| 256 |
+
Error readTemporalProfTraceData();
|
| 257 |
+
|
| 258 |
+
public:
|
| 259 |
+
TextInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer_)
|
| 260 |
+
: DataBuffer(std::move(DataBuffer_)), Line(*DataBuffer, true, '#') {}
|
| 261 |
+
TextInstrProfReader(const TextInstrProfReader &) = delete;
|
| 262 |
+
TextInstrProfReader &operator=(const TextInstrProfReader &) = delete;
|
| 263 |
+
|
| 264 |
+
/// Return true if the given buffer is in text instrprof format.
|
| 265 |
+
static bool hasFormat(const MemoryBuffer &Buffer);
|
| 266 |
+
|
| 267 |
+
// Text format does not have version, so return 0.
|
| 268 |
+
uint64_t getVersion() const override { return 0; }
|
| 269 |
+
|
| 270 |
+
bool isIRLevelProfile() const override {
|
| 271 |
+
return static_cast<bool>(ProfileKind & InstrProfKind::IRInstrumentation);
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
bool hasCSIRLevelProfile() const override {
|
| 275 |
+
return static_cast<bool>(ProfileKind & InstrProfKind::ContextSensitive);
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
bool instrEntryBBEnabled() const override {
|
| 279 |
+
return static_cast<bool>(ProfileKind &
|
| 280 |
+
InstrProfKind::FunctionEntryInstrumentation);
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
bool instrLoopEntriesEnabled() const override {
|
| 284 |
+
return static_cast<bool>(ProfileKind &
|
| 285 |
+
InstrProfKind::LoopEntriesInstrumentation);
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
bool hasSingleByteCoverage() const override {
|
| 289 |
+
return static_cast<bool>(ProfileKind & InstrProfKind::SingleByteCoverage);
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
bool functionEntryOnly() const override {
|
| 293 |
+
return static_cast<bool>(ProfileKind & InstrProfKind::FunctionEntryOnly);
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
bool hasMemoryProfile() const override {
|
| 297 |
+
// TODO: Add support for text format memory profiles.
|
| 298 |
+
return false;
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
bool hasTemporalProfile() const override {
|
| 302 |
+
return static_cast<bool>(ProfileKind & InstrProfKind::TemporalProfile);
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
InstrProfKind getProfileKind() const override { return ProfileKind; }
|
| 306 |
+
|
| 307 |
+
/// Read the header.
|
| 308 |
+
Error readHeader() override;
|
| 309 |
+
|
| 310 |
+
/// Read a single record.
|
| 311 |
+
Error readNextRecord(NamedInstrProfRecord &Record) override;
|
| 312 |
+
|
| 313 |
+
InstrProfSymtab &getSymtab() override {
|
| 314 |
+
assert(Symtab);
|
| 315 |
+
return *Symtab;
|
| 316 |
+
}
|
| 317 |
+
};
|
| 318 |
+
|
| 319 |
+
/// Reader for the raw instrprof binary format from runtime.
|
| 320 |
+
///
|
| 321 |
+
/// This format is a raw memory dump of the instrumentation-based profiling data
|
| 322 |
+
/// from the runtime. It has no index.
|
| 323 |
+
///
|
| 324 |
+
/// Templated on the unsigned type whose size matches pointers on the platform
|
| 325 |
+
/// that wrote the profile.
|
| 326 |
+
template <class IntPtrT>
|
| 327 |
+
class RawInstrProfReader : public InstrProfReader {
|
| 328 |
+
private:
|
| 329 |
+
/// The profile data file contents.
|
| 330 |
+
std::unique_ptr<MemoryBuffer> DataBuffer;
|
| 331 |
+
/// If available, this hold the ProfileData array used to correlate raw
|
| 332 |
+
/// instrumentation data to their functions.
|
| 333 |
+
const InstrProfCorrelatorImpl<IntPtrT> *Correlator;
|
| 334 |
+
/// Fetches debuginfo by build id to correlate profiles.
|
| 335 |
+
const object::BuildIDFetcher *BIDFetcher;
|
| 336 |
+
/// Correlates profiles with build id fetcher by fetching debuginfo with build
|
| 337 |
+
/// ID.
|
| 338 |
+
std::unique_ptr<InstrProfCorrelator> BIDFetcherCorrelator;
|
| 339 |
+
/// Indicates if should use debuginfo or binary to correlate with build id
|
| 340 |
+
/// fetcher.
|
| 341 |
+
InstrProfCorrelator::ProfCorrelatorKind BIDFetcherCorrelatorKind;
|
| 342 |
+
/// A list of timestamps paired with a function name reference.
|
| 343 |
+
std::vector<std::pair<uint64_t, uint64_t>> TemporalProfTimestamps;
|
| 344 |
+
bool ShouldSwapBytes;
|
| 345 |
+
// The value of the version field of the raw profile data header. The lower 32
|
| 346 |
+
// bits specifies the format version and the most significant 32 bits specify
|
| 347 |
+
// the variant types of the profile.
|
| 348 |
+
uint64_t Version;
|
| 349 |
+
uint64_t CountersDelta;
|
| 350 |
+
uint64_t BitmapDelta;
|
| 351 |
+
uint64_t NamesDelta;
|
| 352 |
+
const RawInstrProf::ProfileData<IntPtrT> *Data;
|
| 353 |
+
const RawInstrProf::ProfileData<IntPtrT> *DataEnd;
|
| 354 |
+
const RawInstrProf::VTableProfileData<IntPtrT> *VTableBegin = nullptr;
|
| 355 |
+
const RawInstrProf::VTableProfileData<IntPtrT> *VTableEnd = nullptr;
|
| 356 |
+
const char *CountersStart;
|
| 357 |
+
const char *CountersEnd;
|
| 358 |
+
const char *BitmapStart;
|
| 359 |
+
const char *BitmapEnd;
|
| 360 |
+
const char *NamesStart;
|
| 361 |
+
const char *NamesEnd;
|
| 362 |
+
const char *VNamesStart = nullptr;
|
| 363 |
+
const char *VNamesEnd = nullptr;
|
| 364 |
+
// After value profile is all read, this pointer points to
|
| 365 |
+
// the header of next profile data (if exists)
|
| 366 |
+
const uint8_t *ValueDataStart;
|
| 367 |
+
uint32_t ValueKindLast;
|
| 368 |
+
uint32_t CurValueDataSize;
|
| 369 |
+
std::vector<llvm::object::BuildID> BinaryIds;
|
| 370 |
+
|
| 371 |
+
std::function<void(Error)> Warn;
|
| 372 |
+
|
| 373 |
+
/// Maxium counter value 2^56.
|
| 374 |
+
static const uint64_t MaxCounterValue = (1ULL << 56);
|
| 375 |
+
|
| 376 |
+
public:
|
| 377 |
+
RawInstrProfReader(
|
| 378 |
+
std::unique_ptr<MemoryBuffer> DataBuffer,
|
| 379 |
+
const InstrProfCorrelator *Correlator,
|
| 380 |
+
const object::BuildIDFetcher *BIDFetcher,
|
| 381 |
+
const InstrProfCorrelator::ProfCorrelatorKind BIDFetcherCorrelatorKind,
|
| 382 |
+
std::function<void(Error)> Warn)
|
| 383 |
+
: DataBuffer(std::move(DataBuffer)),
|
| 384 |
+
Correlator(dyn_cast_or_null<const InstrProfCorrelatorImpl<IntPtrT>>(
|
| 385 |
+
Correlator)),
|
| 386 |
+
BIDFetcher(BIDFetcher),
|
| 387 |
+
BIDFetcherCorrelatorKind(BIDFetcherCorrelatorKind), Warn(Warn) {}
|
| 388 |
+
|
| 389 |
+
RawInstrProfReader(const RawInstrProfReader &) = delete;
|
| 390 |
+
RawInstrProfReader &operator=(const RawInstrProfReader &) = delete;
|
| 391 |
+
|
| 392 |
+
static bool hasFormat(const MemoryBuffer &DataBuffer);
|
| 393 |
+
Error readHeader() override;
|
| 394 |
+
Error readNextRecord(NamedInstrProfRecord &Record) override;
|
| 395 |
+
Error readBinaryIds(std::vector<llvm::object::BuildID> &BinaryIds) override;
|
| 396 |
+
Error printBinaryIds(raw_ostream &OS) override;
|
| 397 |
+
|
| 398 |
+
uint64_t getVersion() const override { return Version; }
|
| 399 |
+
|
| 400 |
+
bool isIRLevelProfile() const override {
|
| 401 |
+
return (Version & VARIANT_MASK_IR_PROF) != 0;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
bool hasCSIRLevelProfile() const override {
|
| 405 |
+
return (Version & VARIANT_MASK_CSIR_PROF) != 0;
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
bool instrEntryBBEnabled() const override {
|
| 409 |
+
return (Version & VARIANT_MASK_INSTR_ENTRY) != 0;
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
bool instrLoopEntriesEnabled() const override {
|
| 413 |
+
return (Version & VARIANT_MASK_INSTR_LOOP_ENTRIES) != 0;
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
bool hasSingleByteCoverage() const override {
|
| 417 |
+
return (Version & VARIANT_MASK_BYTE_COVERAGE) != 0;
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
bool functionEntryOnly() const override {
|
| 421 |
+
return (Version & VARIANT_MASK_FUNCTION_ENTRY_ONLY) != 0;
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
bool hasMemoryProfile() const override {
|
| 425 |
+
// Memory profiles have a separate raw format, so this should never be set.
|
| 426 |
+
assert(!(Version & VARIANT_MASK_MEMPROF));
|
| 427 |
+
return false;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
bool hasTemporalProfile() const override {
|
| 431 |
+
return (Version & VARIANT_MASK_TEMPORAL_PROF) != 0;
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
/// Returns a BitsetEnum describing the attributes of the raw instr profile.
|
| 435 |
+
InstrProfKind getProfileKind() const override;
|
| 436 |
+
|
| 437 |
+
InstrProfSymtab &getSymtab() override {
|
| 438 |
+
assert(Symtab.get());
|
| 439 |
+
return *Symtab.get();
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
SmallVector<TemporalProfTraceTy> &
|
| 443 |
+
getTemporalProfTraces(std::optional<uint64_t> Weight = {}) override;
|
| 444 |
+
|
| 445 |
+
private:
|
| 446 |
+
Error createSymtab(InstrProfSymtab &Symtab);
|
| 447 |
+
Error readNextHeader(const char *CurrentPos);
|
| 448 |
+
Error readHeader(const RawInstrProf::Header &Header);
|
| 449 |
+
|
| 450 |
+
template <class IntT> IntT swap(IntT Int) const {
|
| 451 |
+
return ShouldSwapBytes ? llvm::byteswap(Int) : Int;
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
llvm::endianness getDataEndianness() const {
|
| 455 |
+
if (!ShouldSwapBytes)
|
| 456 |
+
return llvm::endianness::native;
|
| 457 |
+
if (llvm::endianness::native == llvm::endianness::little)
|
| 458 |
+
return llvm::endianness::big;
|
| 459 |
+
else
|
| 460 |
+
return llvm::endianness::little;
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
inline uint8_t getNumPaddingBytes(uint64_t SizeInBytes) {
|
| 464 |
+
return 7 & (sizeof(uint64_t) - SizeInBytes % sizeof(uint64_t));
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
Error readName(NamedInstrProfRecord &Record);
|
| 468 |
+
Error readFuncHash(NamedInstrProfRecord &Record);
|
| 469 |
+
Error readRawCounts(InstrProfRecord &Record);
|
| 470 |
+
Error readRawBitmapBytes(InstrProfRecord &Record);
|
| 471 |
+
Error readValueProfilingData(InstrProfRecord &Record);
|
| 472 |
+
bool atEnd() const { return Data == DataEnd; }
|
| 473 |
+
|
| 474 |
+
void advanceData() {
|
| 475 |
+
// `CountersDelta` is a constant zero when using debug info correlation.
|
| 476 |
+
if (!Correlator && !BIDFetcherCorrelator) {
|
| 477 |
+
// The initial CountersDelta is the in-memory address difference between
|
| 478 |
+
// the data and counts sections:
|
| 479 |
+
// start(__llvm_prf_cnts) - start(__llvm_prf_data)
|
| 480 |
+
// As we advance to the next record, we maintain the correct CountersDelta
|
| 481 |
+
// with respect to the next record.
|
| 482 |
+
CountersDelta -= sizeof(*Data);
|
| 483 |
+
BitmapDelta -= sizeof(*Data);
|
| 484 |
+
}
|
| 485 |
+
Data++;
|
| 486 |
+
ValueDataStart += CurValueDataSize;
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
const char *getNextHeaderPos() const {
|
| 490 |
+
assert(atEnd());
|
| 491 |
+
return (const char *)ValueDataStart;
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
StringRef getName(uint64_t NameRef) const {
|
| 495 |
+
return Symtab->getFuncOrVarName(swap(NameRef));
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
int getCounterTypeSize() const {
|
| 499 |
+
return hasSingleByteCoverage() ? sizeof(uint8_t) : sizeof(uint64_t);
|
| 500 |
+
}
|
| 501 |
+
};
|
| 502 |
+
|
| 503 |
+
using RawInstrProfReader32 = RawInstrProfReader<uint32_t>;
|
| 504 |
+
using RawInstrProfReader64 = RawInstrProfReader<uint64_t>;
|
| 505 |
+
|
| 506 |
+
namespace IndexedInstrProf {
|
| 507 |
+
|
| 508 |
+
enum class HashT : uint32_t;
|
| 509 |
+
|
| 510 |
+
} // end namespace IndexedInstrProf
|
| 511 |
+
|
| 512 |
+
/// Trait for lookups into the on-disk hash table for the binary instrprof
|
| 513 |
+
/// format.
|
| 514 |
+
class InstrProfLookupTrait {
|
| 515 |
+
std::vector<NamedInstrProfRecord> DataBuffer;
|
| 516 |
+
IndexedInstrProf::HashT HashType;
|
| 517 |
+
unsigned FormatVersion;
|
| 518 |
+
// Endianness of the input value profile data.
|
| 519 |
+
// It should be LE by default, but can be changed
|
| 520 |
+
// for testing purpose.
|
| 521 |
+
llvm::endianness ValueProfDataEndianness = llvm::endianness::little;
|
| 522 |
+
|
| 523 |
+
public:
|
| 524 |
+
InstrProfLookupTrait(IndexedInstrProf::HashT HashType, unsigned FormatVersion)
|
| 525 |
+
: HashType(HashType), FormatVersion(FormatVersion) {}
|
| 526 |
+
|
| 527 |
+
using data_type = ArrayRef<NamedInstrProfRecord>;
|
| 528 |
+
|
| 529 |
+
using internal_key_type = StringRef;
|
| 530 |
+
using external_key_type = StringRef;
|
| 531 |
+
using hash_value_type = uint64_t;
|
| 532 |
+
using offset_type = uint64_t;
|
| 533 |
+
|
| 534 |
+
static bool EqualKey(StringRef A, StringRef B) { return A == B; }
|
| 535 |
+
static StringRef GetInternalKey(StringRef K) { return K; }
|
| 536 |
+
static StringRef GetExternalKey(StringRef K) { return K; }
|
| 537 |
+
|
| 538 |
+
hash_value_type ComputeHash(StringRef K);
|
| 539 |
+
|
| 540 |
+
static std::pair<offset_type, offset_type>
|
| 541 |
+
ReadKeyDataLength(const unsigned char *&D) {
|
| 542 |
+
using namespace support;
|
| 543 |
+
|
| 544 |
+
offset_type KeyLen =
|
| 545 |
+
endian::readNext<offset_type, llvm::endianness::little>(D);
|
| 546 |
+
offset_type DataLen =
|
| 547 |
+
endian::readNext<offset_type, llvm::endianness::little>(D);
|
| 548 |
+
return std::make_pair(KeyLen, DataLen);
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
StringRef ReadKey(const unsigned char *D, offset_type N) {
|
| 552 |
+
return StringRef((const char *)D, N);
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
bool readValueProfilingData(const unsigned char *&D,
|
| 556 |
+
const unsigned char *const End);
|
| 557 |
+
data_type ReadData(StringRef K, const unsigned char *D, offset_type N);
|
| 558 |
+
|
| 559 |
+
// Used for testing purpose only.
|
| 560 |
+
void setValueProfDataEndianness(llvm::endianness Endianness) {
|
| 561 |
+
ValueProfDataEndianness = Endianness;
|
| 562 |
+
}
|
| 563 |
+
};
|
| 564 |
+
|
| 565 |
+
struct InstrProfReaderIndexBase {
|
| 566 |
+
virtual ~InstrProfReaderIndexBase() = default;
|
| 567 |
+
|
| 568 |
+
// Read all the profile records with the same key pointed to the current
|
| 569 |
+
// iterator.
|
| 570 |
+
virtual Error getRecords(ArrayRef<NamedInstrProfRecord> &Data) = 0;
|
| 571 |
+
|
| 572 |
+
// Read all the profile records with the key equal to FuncName
|
| 573 |
+
virtual Error getRecords(StringRef FuncName,
|
| 574 |
+
ArrayRef<NamedInstrProfRecord> &Data) = 0;
|
| 575 |
+
virtual void advanceToNextKey() = 0;
|
| 576 |
+
virtual bool atEnd() const = 0;
|
| 577 |
+
virtual void setValueProfDataEndianness(llvm::endianness Endianness) = 0;
|
| 578 |
+
virtual uint64_t getVersion() const = 0;
|
| 579 |
+
virtual bool isIRLevelProfile() const = 0;
|
| 580 |
+
virtual bool hasCSIRLevelProfile() const = 0;
|
| 581 |
+
virtual bool instrEntryBBEnabled() const = 0;
|
| 582 |
+
virtual bool instrLoopEntriesEnabled() const = 0;
|
| 583 |
+
virtual bool hasSingleByteCoverage() const = 0;
|
| 584 |
+
virtual bool functionEntryOnly() const = 0;
|
| 585 |
+
virtual bool hasMemoryProfile() const = 0;
|
| 586 |
+
virtual bool hasTemporalProfile() const = 0;
|
| 587 |
+
virtual InstrProfKind getProfileKind() const = 0;
|
| 588 |
+
virtual Error populateSymtab(InstrProfSymtab &) = 0;
|
| 589 |
+
};
|
| 590 |
+
|
| 591 |
+
using OnDiskHashTableImplV3 =
|
| 592 |
+
OnDiskIterableChainedHashTable<InstrProfLookupTrait>;
|
| 593 |
+
|
| 594 |
+
using MemProfRecordHashTable =
|
| 595 |
+
OnDiskIterableChainedHashTable<memprof::RecordLookupTrait>;
|
| 596 |
+
using MemProfFrameHashTable =
|
| 597 |
+
OnDiskIterableChainedHashTable<memprof::FrameLookupTrait>;
|
| 598 |
+
using MemProfCallStackHashTable =
|
| 599 |
+
OnDiskIterableChainedHashTable<memprof::CallStackLookupTrait>;
|
| 600 |
+
|
| 601 |
+
template <typename HashTableImpl>
|
| 602 |
+
class InstrProfReaderItaniumRemapper;
|
| 603 |
+
|
| 604 |
+
template <typename HashTableImpl>
|
| 605 |
+
class InstrProfReaderIndex : public InstrProfReaderIndexBase {
|
| 606 |
+
private:
|
| 607 |
+
std::unique_ptr<HashTableImpl> HashTable;
|
| 608 |
+
typename HashTableImpl::data_iterator RecordIterator;
|
| 609 |
+
uint64_t FormatVersion;
|
| 610 |
+
|
| 611 |
+
friend class InstrProfReaderItaniumRemapper<HashTableImpl>;
|
| 612 |
+
|
| 613 |
+
public:
|
| 614 |
+
InstrProfReaderIndex(const unsigned char *Buckets,
|
| 615 |
+
const unsigned char *const Payload,
|
| 616 |
+
const unsigned char *const Base,
|
| 617 |
+
IndexedInstrProf::HashT HashType, uint64_t Version);
|
| 618 |
+
~InstrProfReaderIndex() override = default;
|
| 619 |
+
|
| 620 |
+
Error getRecords(ArrayRef<NamedInstrProfRecord> &Data) override;
|
| 621 |
+
Error getRecords(StringRef FuncName,
|
| 622 |
+
ArrayRef<NamedInstrProfRecord> &Data) override;
|
| 623 |
+
void advanceToNextKey() override { RecordIterator++; }
|
| 624 |
+
|
| 625 |
+
bool atEnd() const override {
|
| 626 |
+
return RecordIterator == HashTable->data_end();
|
| 627 |
+
}
|
| 628 |
+
|
| 629 |
+
void setValueProfDataEndianness(llvm::endianness Endianness) override {
|
| 630 |
+
HashTable->getInfoObj().setValueProfDataEndianness(Endianness);
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
uint64_t getVersion() const override { return GET_VERSION(FormatVersion); }
|
| 634 |
+
|
| 635 |
+
bool isIRLevelProfile() const override {
|
| 636 |
+
return (FormatVersion & VARIANT_MASK_IR_PROF) != 0;
|
| 637 |
+
}
|
| 638 |
+
|
| 639 |
+
bool hasCSIRLevelProfile() const override {
|
| 640 |
+
return (FormatVersion & VARIANT_MASK_CSIR_PROF) != 0;
|
| 641 |
+
}
|
| 642 |
+
|
| 643 |
+
bool instrEntryBBEnabled() const override {
|
| 644 |
+
return (FormatVersion & VARIANT_MASK_INSTR_ENTRY) != 0;
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
bool instrLoopEntriesEnabled() const override {
|
| 648 |
+
return (FormatVersion & VARIANT_MASK_INSTR_LOOP_ENTRIES) != 0;
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
bool hasSingleByteCoverage() const override {
|
| 652 |
+
return (FormatVersion & VARIANT_MASK_BYTE_COVERAGE) != 0;
|
| 653 |
+
}
|
| 654 |
+
|
| 655 |
+
bool functionEntryOnly() const override {
|
| 656 |
+
return (FormatVersion & VARIANT_MASK_FUNCTION_ENTRY_ONLY) != 0;
|
| 657 |
+
}
|
| 658 |
+
|
| 659 |
+
bool hasMemoryProfile() const override {
|
| 660 |
+
return (FormatVersion & VARIANT_MASK_MEMPROF) != 0;
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
bool hasTemporalProfile() const override {
|
| 664 |
+
return (FormatVersion & VARIANT_MASK_TEMPORAL_PROF) != 0;
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
InstrProfKind getProfileKind() const override;
|
| 668 |
+
|
| 669 |
+
Error populateSymtab(InstrProfSymtab &Symtab) override {
|
| 670 |
+
// FIXME: the create method calls 'finalizeSymtab' and sorts a bunch of
|
| 671 |
+
// arrays/maps. Since there are other data sources other than 'HashTable' to
|
| 672 |
+
// populate a symtab, it might make sense to have something like this
|
| 673 |
+
// 1. Let each data source populate Symtab and init the arrays/maps without
|
| 674 |
+
// calling 'finalizeSymtab'
|
| 675 |
+
// 2. Call 'finalizeSymtab' once to get all arrays/maps sorted if needed.
|
| 676 |
+
return Symtab.create(HashTable->keys());
|
| 677 |
+
}
|
| 678 |
+
};
|
| 679 |
+
|
| 680 |
+
/// Name matcher supporting fuzzy matching of symbol names to names in profiles.
|
| 681 |
+
class InstrProfReaderRemapper {
|
| 682 |
+
public:
|
| 683 |
+
virtual ~InstrProfReaderRemapper() = default;
|
| 684 |
+
virtual Error populateRemappings() { return Error::success(); }
|
| 685 |
+
virtual Error getRecords(StringRef FuncName,
|
| 686 |
+
ArrayRef<NamedInstrProfRecord> &Data) = 0;
|
| 687 |
+
};
|
| 688 |
+
|
| 689 |
+
class IndexedMemProfReader {
|
| 690 |
+
private:
|
| 691 |
+
/// The MemProf version.
|
| 692 |
+
memprof::IndexedVersion Version =
|
| 693 |
+
static_cast<memprof::IndexedVersion>(memprof::MinimumSupportedVersion);
|
| 694 |
+
/// MemProf summary (if available, version >= 4).
|
| 695 |
+
std::unique_ptr<memprof::MemProfSummary> MemProfSum;
|
| 696 |
+
/// MemProf profile schema (if available).
|
| 697 |
+
memprof::MemProfSchema Schema;
|
| 698 |
+
/// MemProf record profile data on-disk indexed via llvm::md5(FunctionName).
|
| 699 |
+
std::unique_ptr<MemProfRecordHashTable> MemProfRecordTable;
|
| 700 |
+
/// MemProf frame profile data on-disk indexed via frame id.
|
| 701 |
+
std::unique_ptr<MemProfFrameHashTable> MemProfFrameTable;
|
| 702 |
+
/// MemProf call stack data on-disk indexed via call stack id.
|
| 703 |
+
std::unique_ptr<MemProfCallStackHashTable> MemProfCallStackTable;
|
| 704 |
+
/// The starting address of the frame array.
|
| 705 |
+
const unsigned char *FrameBase = nullptr;
|
| 706 |
+
/// The starting address of the call stack array.
|
| 707 |
+
const unsigned char *CallStackBase = nullptr;
|
| 708 |
+
// The number of elements in the radix tree array.
|
| 709 |
+
unsigned RadixTreeSize = 0;
|
| 710 |
+
/// The data access profiles, deserialized from binary data.
|
| 711 |
+
std::unique_ptr<memprof::DataAccessProfData> DataAccessProfileData;
|
| 712 |
+
|
| 713 |
+
Error deserializeV2(const unsigned char *Start, const unsigned char *Ptr);
|
| 714 |
+
Error deserializeRadixTreeBased(const unsigned char *Start,
|
| 715 |
+
const unsigned char *Ptr,
|
| 716 |
+
memprof::IndexedVersion Version);
|
| 717 |
+
|
| 718 |
+
public:
|
| 719 |
+
IndexedMemProfReader() = default;
|
| 720 |
+
|
| 721 |
+
Error deserialize(const unsigned char *Start, uint64_t MemProfOffset);
|
| 722 |
+
|
| 723 |
+
Expected<memprof::MemProfRecord>
|
| 724 |
+
getMemProfRecord(const uint64_t FuncNameHash) const;
|
| 725 |
+
|
| 726 |
+
DenseMap<uint64_t, SmallVector<memprof::CallEdgeTy, 0>>
|
| 727 |
+
getMemProfCallerCalleePairs() const;
|
| 728 |
+
|
| 729 |
+
// Return the entire MemProf profile.
|
| 730 |
+
memprof::AllMemProfData getAllMemProfData() const;
|
| 731 |
+
|
| 732 |
+
memprof::MemProfSummary *getSummary() const { return MemProfSum.get(); }
|
| 733 |
+
};
|
| 734 |
+
|
| 735 |
+
/// Reader for the indexed binary instrprof format.
|
| 736 |
+
class IndexedInstrProfReader : public InstrProfReader {
|
| 737 |
+
private:
|
| 738 |
+
/// The profile data file contents.
|
| 739 |
+
std::unique_ptr<MemoryBuffer> DataBuffer;
|
| 740 |
+
/// The profile remapping file contents.
|
| 741 |
+
std::unique_ptr<MemoryBuffer> RemappingBuffer;
|
| 742 |
+
/// The index into the profile data.
|
| 743 |
+
std::unique_ptr<InstrProfReaderIndexBase> Index;
|
| 744 |
+
/// The profile remapping file contents.
|
| 745 |
+
std::unique_ptr<InstrProfReaderRemapper> Remapper;
|
| 746 |
+
/// Profile summary data.
|
| 747 |
+
std::unique_ptr<ProfileSummary> Summary;
|
| 748 |
+
/// Context sensitive profile summary data.
|
| 749 |
+
std::unique_ptr<ProfileSummary> CS_Summary;
|
| 750 |
+
IndexedMemProfReader MemProfReader;
|
| 751 |
+
/// The compressed vtable names, to be used for symtab construction.
|
| 752 |
+
/// A compiler that reads indexed profiles could construct symtab from module
|
| 753 |
+
/// IR so it doesn't need the decompressed names.
|
| 754 |
+
StringRef VTableName;
|
| 755 |
+
/// A memory buffer holding binary ids.
|
| 756 |
+
ArrayRef<uint8_t> BinaryIdsBuffer;
|
| 757 |
+
|
| 758 |
+
// Index to the current record in the record array.
|
| 759 |
+
unsigned RecordIndex = 0;
|
| 760 |
+
|
| 761 |
+
// Read the profile summary. Return a pointer pointing to one byte past the
|
| 762 |
+
// end of the summary data if it exists or the input \c Cur.
|
| 763 |
+
// \c UseCS indicates whether to use the context-sensitive profile summary.
|
| 764 |
+
const unsigned char *readSummary(IndexedInstrProf::ProfVersion Version,
|
| 765 |
+
const unsigned char *Cur, bool UseCS);
|
| 766 |
+
|
| 767 |
+
public:
|
| 768 |
+
IndexedInstrProfReader(
|
| 769 |
+
std::unique_ptr<MemoryBuffer> DataBuffer,
|
| 770 |
+
std::unique_ptr<MemoryBuffer> RemappingBuffer = nullptr)
|
| 771 |
+
: DataBuffer(std::move(DataBuffer)),
|
| 772 |
+
RemappingBuffer(std::move(RemappingBuffer)) {}
|
| 773 |
+
IndexedInstrProfReader(const IndexedInstrProfReader &) = delete;
|
| 774 |
+
IndexedInstrProfReader &operator=(const IndexedInstrProfReader &) = delete;
|
| 775 |
+
|
| 776 |
+
/// Return the profile version.
|
| 777 |
+
uint64_t getVersion() const override { return Index->getVersion(); }
|
| 778 |
+
bool isIRLevelProfile() const override { return Index->isIRLevelProfile(); }
|
| 779 |
+
bool hasCSIRLevelProfile() const override {
|
| 780 |
+
return Index->hasCSIRLevelProfile();
|
| 781 |
+
}
|
| 782 |
+
|
| 783 |
+
bool instrEntryBBEnabled() const override {
|
| 784 |
+
return Index->instrEntryBBEnabled();
|
| 785 |
+
}
|
| 786 |
+
|
| 787 |
+
bool instrLoopEntriesEnabled() const override {
|
| 788 |
+
return Index->instrLoopEntriesEnabled();
|
| 789 |
+
}
|
| 790 |
+
|
| 791 |
+
bool hasSingleByteCoverage() const override {
|
| 792 |
+
return Index->hasSingleByteCoverage();
|
| 793 |
+
}
|
| 794 |
+
|
| 795 |
+
bool functionEntryOnly() const override { return Index->functionEntryOnly(); }
|
| 796 |
+
|
| 797 |
+
bool hasMemoryProfile() const override { return Index->hasMemoryProfile(); }
|
| 798 |
+
|
| 799 |
+
bool hasTemporalProfile() const override {
|
| 800 |
+
return Index->hasTemporalProfile();
|
| 801 |
+
}
|
| 802 |
+
|
| 803 |
+
/// Returns a BitsetEnum describing the attributes of the indexed instr
|
| 804 |
+
/// profile.
|
| 805 |
+
InstrProfKind getProfileKind() const override {
|
| 806 |
+
return Index->getProfileKind();
|
| 807 |
+
}
|
| 808 |
+
|
| 809 |
+
/// Return true if the given buffer is in an indexed instrprof format.
|
| 810 |
+
static bool hasFormat(const MemoryBuffer &DataBuffer);
|
| 811 |
+
|
| 812 |
+
/// Read the file header.
|
| 813 |
+
Error readHeader() override;
|
| 814 |
+
/// Read a single record.
|
| 815 |
+
Error readNextRecord(NamedInstrProfRecord &Record) override;
|
| 816 |
+
|
| 817 |
+
/// Return the NamedInstrProfRecord associated with FuncName and FuncHash.
|
| 818 |
+
/// When return a hash_mismatch error and MismatchedFuncSum is not nullptr,
|
| 819 |
+
/// the sum of all counters in the mismatched function will be set to
|
| 820 |
+
/// MismatchedFuncSum. If there are multiple instances of mismatched
|
| 821 |
+
/// functions, MismatchedFuncSum returns the maximum. If \c FuncName is not
|
| 822 |
+
/// found, try to lookup \c DeprecatedFuncName to handle profiles built by
|
| 823 |
+
/// older compilers.
|
| 824 |
+
Expected<InstrProfRecord>
|
| 825 |
+
getInstrProfRecord(StringRef FuncName, uint64_t FuncHash,
|
| 826 |
+
StringRef DeprecatedFuncName = "",
|
| 827 |
+
uint64_t *MismatchedFuncSum = nullptr);
|
| 828 |
+
|
| 829 |
+
/// Return the memprof record for the function identified by
|
| 830 |
+
/// llvm::md5(Name).
|
| 831 |
+
Expected<memprof::MemProfRecord> getMemProfRecord(uint64_t FuncNameHash) {
|
| 832 |
+
return MemProfReader.getMemProfRecord(FuncNameHash);
|
| 833 |
+
}
|
| 834 |
+
|
| 835 |
+
DenseMap<uint64_t, SmallVector<memprof::CallEdgeTy, 0>>
|
| 836 |
+
getMemProfCallerCalleePairs() {
|
| 837 |
+
return MemProfReader.getMemProfCallerCalleePairs();
|
| 838 |
+
}
|
| 839 |
+
|
| 840 |
+
memprof::AllMemProfData getAllMemProfData() const {
|
| 841 |
+
return MemProfReader.getAllMemProfData();
|
| 842 |
+
}
|
| 843 |
+
|
| 844 |
+
/// Fill Counts with the profile data for the given function name.
|
| 845 |
+
Error getFunctionCounts(StringRef FuncName, uint64_t FuncHash,
|
| 846 |
+
std::vector<uint64_t> &Counts);
|
| 847 |
+
|
| 848 |
+
/// Fill Bitmap with the profile data for the given function name.
|
| 849 |
+
Error getFunctionBitmap(StringRef FuncName, uint64_t FuncHash,
|
| 850 |
+
BitVector &Bitmap);
|
| 851 |
+
|
| 852 |
+
/// Return the maximum of all known function counts.
|
| 853 |
+
/// \c UseCS indicates whether to use the context-sensitive count.
|
| 854 |
+
uint64_t getMaximumFunctionCount(bool UseCS) {
|
| 855 |
+
if (UseCS) {
|
| 856 |
+
assert(CS_Summary && "No context sensitive profile summary");
|
| 857 |
+
return CS_Summary->getMaxFunctionCount();
|
| 858 |
+
} else {
|
| 859 |
+
assert(Summary && "No profile summary");
|
| 860 |
+
return Summary->getMaxFunctionCount();
|
| 861 |
+
}
|
| 862 |
+
}
|
| 863 |
+
|
| 864 |
+
/// Factory method to create an indexed reader.
|
| 865 |
+
static Expected<std::unique_ptr<IndexedInstrProfReader>>
|
| 866 |
+
create(const Twine &Path, vfs::FileSystem &FS,
|
| 867 |
+
const Twine &RemappingPath = "");
|
| 868 |
+
|
| 869 |
+
static Expected<std::unique_ptr<IndexedInstrProfReader>>
|
| 870 |
+
create(std::unique_ptr<MemoryBuffer> Buffer,
|
| 871 |
+
std::unique_ptr<MemoryBuffer> RemappingBuffer = nullptr);
|
| 872 |
+
|
| 873 |
+
// Used for testing purpose only.
|
| 874 |
+
void setValueProfDataEndianness(llvm::endianness Endianness) {
|
| 875 |
+
Index->setValueProfDataEndianness(Endianness);
|
| 876 |
+
}
|
| 877 |
+
|
| 878 |
+
// See description in the base class. This interface is designed
|
| 879 |
+
// to be used by llvm-profdata (for dumping). Avoid using this when
|
| 880 |
+
// the client is the compiler.
|
| 881 |
+
InstrProfSymtab &getSymtab() override;
|
| 882 |
+
|
| 883 |
+
/// Return the profile summary.
|
| 884 |
+
/// \c UseCS indicates whether to use the context-sensitive summary.
|
| 885 |
+
ProfileSummary &getSummary(bool UseCS) {
|
| 886 |
+
if (UseCS) {
|
| 887 |
+
assert(CS_Summary && "No context sensitive summary");
|
| 888 |
+
return *CS_Summary;
|
| 889 |
+
} else {
|
| 890 |
+
assert(Summary && "No profile summary");
|
| 891 |
+
return *Summary;
|
| 892 |
+
}
|
| 893 |
+
}
|
| 894 |
+
|
| 895 |
+
/// Return the MemProf summary. Will be null if unavailable (version < 4).
|
| 896 |
+
memprof::MemProfSummary *getMemProfSummary() const {
|
| 897 |
+
return MemProfReader.getSummary();
|
| 898 |
+
}
|
| 899 |
+
|
| 900 |
+
Error readBinaryIds(std::vector<llvm::object::BuildID> &BinaryIds) override;
|
| 901 |
+
Error printBinaryIds(raw_ostream &OS) override;
|
| 902 |
+
};
|
| 903 |
+
|
| 904 |
+
} // end namespace llvm
|
| 905 |
+
|
| 906 |
+
#endif // LLVM_PROFILEDATA_INSTRPROFREADER_H
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/InstrProfWriter.h
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- InstrProfWriter.h - Instrumented profiling writer --------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file contains support for writing profiling data for instrumentation
|
| 10 |
+
// based PGO and coverage.
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#ifndef LLVM_PROFILEDATA_INSTRPROFWRITER_H
|
| 15 |
+
#define LLVM_PROFILEDATA_INSTRPROFWRITER_H
|
| 16 |
+
|
| 17 |
+
#include "llvm/ADT/DenseMap.h"
|
| 18 |
+
#include "llvm/ADT/MapVector.h"
|
| 19 |
+
#include "llvm/ADT/StringMap.h"
|
| 20 |
+
#include "llvm/IR/GlobalValue.h"
|
| 21 |
+
#include "llvm/Object/BuildID.h"
|
| 22 |
+
#include "llvm/ProfileData/DataAccessProf.h"
|
| 23 |
+
#include "llvm/ProfileData/IndexedMemProfData.h"
|
| 24 |
+
#include "llvm/ProfileData/InstrProf.h"
|
| 25 |
+
#include "llvm/ProfileData/MemProfSummaryBuilder.h"
|
| 26 |
+
#include "llvm/Support/Error.h"
|
| 27 |
+
#include <cstdint>
|
| 28 |
+
#include <memory>
|
| 29 |
+
#include <random>
|
| 30 |
+
|
| 31 |
+
namespace llvm {
|
| 32 |
+
|
| 33 |
+
/// Writer for instrumentation based profile data.
|
| 34 |
+
class InstrProfRecordWriterTrait;
|
| 35 |
+
class ProfOStream;
|
| 36 |
+
class MemoryBuffer;
|
| 37 |
+
class raw_fd_ostream;
|
| 38 |
+
|
| 39 |
+
class InstrProfWriter {
|
| 40 |
+
public:
|
| 41 |
+
using ProfilingData = SmallDenseMap<uint64_t, InstrProfRecord>;
|
| 42 |
+
|
| 43 |
+
private:
|
| 44 |
+
bool Sparse;
|
| 45 |
+
StringMap<ProfilingData> FunctionData;
|
| 46 |
+
/// The maximum length of a single temporal profile trace.
|
| 47 |
+
uint64_t MaxTemporalProfTraceLength;
|
| 48 |
+
/// The maximum number of stored temporal profile traces.
|
| 49 |
+
uint64_t TemporalProfTraceReservoirSize;
|
| 50 |
+
/// The total number of temporal profile traces seen.
|
| 51 |
+
uint64_t TemporalProfTraceStreamSize = 0;
|
| 52 |
+
/// The list of temporal profile traces.
|
| 53 |
+
SmallVector<TemporalProfTraceTy> TemporalProfTraces;
|
| 54 |
+
std::mt19937 RNG;
|
| 55 |
+
|
| 56 |
+
// The MemProf data.
|
| 57 |
+
memprof::IndexedMemProfData MemProfData;
|
| 58 |
+
|
| 59 |
+
// List of binary ids.
|
| 60 |
+
std::vector<llvm::object::BuildID> BinaryIds;
|
| 61 |
+
|
| 62 |
+
// Read the vtable names from raw instr profile reader.
|
| 63 |
+
StringSet<> VTableNames;
|
| 64 |
+
|
| 65 |
+
// An enum describing the attributes of the profile.
|
| 66 |
+
InstrProfKind ProfileKind = InstrProfKind::Unknown;
|
| 67 |
+
// Use raw pointer here for the incomplete type object.
|
| 68 |
+
InstrProfRecordWriterTrait *InfoObj;
|
| 69 |
+
|
| 70 |
+
// Temporary support for writing the previous version of the format, to enable
|
| 71 |
+
// some forward compatibility. Currently this suppresses the writing of the
|
| 72 |
+
// new vtable names section and header fields.
|
| 73 |
+
// TODO: Consider enabling this with future version changes as well, to ease
|
| 74 |
+
// deployment of newer versions of llvm-profdata.
|
| 75 |
+
bool WritePrevVersion = false;
|
| 76 |
+
|
| 77 |
+
// The MemProf version we should write.
|
| 78 |
+
memprof::IndexedVersion MemProfVersionRequested;
|
| 79 |
+
|
| 80 |
+
// Whether to serialize the full schema.
|
| 81 |
+
bool MemProfFullSchema;
|
| 82 |
+
|
| 83 |
+
// Whether to generated random memprof hotness for testing.
|
| 84 |
+
bool MemprofGenerateRandomHotness;
|
| 85 |
+
|
| 86 |
+
std::unique_ptr<memprof::DataAccessProfData> DataAccessProfileData;
|
| 87 |
+
|
| 88 |
+
// MemProf summary builder to which records are added as MemProf data is added
|
| 89 |
+
// to the writer.
|
| 90 |
+
memprof::MemProfSummaryBuilder MemProfSumBuilder;
|
| 91 |
+
|
| 92 |
+
public:
|
| 93 |
+
// For memprof testing, random hotness can be assigned to the contexts if
|
| 94 |
+
// MemprofGenerateRandomHotness is enabled. The random seed can be either
|
| 95 |
+
// provided by MemprofGenerateRandomHotnessSeed, or if that is 0, one will be
|
| 96 |
+
// generated in the writer using the current time.
|
| 97 |
+
InstrProfWriter(bool Sparse = false,
|
| 98 |
+
uint64_t TemporalProfTraceReservoirSize = 0,
|
| 99 |
+
uint64_t MaxTemporalProfTraceLength = 0,
|
| 100 |
+
bool WritePrevVersion = false,
|
| 101 |
+
memprof::IndexedVersion MemProfVersionRequested =
|
| 102 |
+
static_cast<memprof::IndexedVersion>(
|
| 103 |
+
memprof::MinimumSupportedVersion),
|
| 104 |
+
bool MemProfFullSchema = false,
|
| 105 |
+
bool MemprofGenerateRandomHotness = false,
|
| 106 |
+
unsigned MemprofGenerateRandomHotnessSeed = 0);
|
| 107 |
+
~InstrProfWriter();
|
| 108 |
+
|
| 109 |
+
StringMap<ProfilingData> &getProfileData() { return FunctionData; }
|
| 110 |
+
|
| 111 |
+
/// Add function counts for the given function. If there are already counts
|
| 112 |
+
/// for this function and the hash and number of counts match, each counter is
|
| 113 |
+
/// summed. Optionally scale counts by \p Weight.
|
| 114 |
+
void addRecord(NamedInstrProfRecord &&I, uint64_t Weight,
|
| 115 |
+
function_ref<void(Error)> Warn);
|
| 116 |
+
void addRecord(NamedInstrProfRecord &&I, function_ref<void(Error)> Warn) {
|
| 117 |
+
addRecord(std::move(I), 1, Warn);
|
| 118 |
+
}
|
| 119 |
+
void addVTableName(StringRef VTableName) { VTableNames.insert(VTableName); }
|
| 120 |
+
|
| 121 |
+
/// Add \p SrcTraces using reservoir sampling where \p SrcStreamSize is the
|
| 122 |
+
/// total number of temporal profiling traces the source has seen.
|
| 123 |
+
void addTemporalProfileTraces(SmallVectorImpl<TemporalProfTraceTy> &SrcTraces,
|
| 124 |
+
uint64_t SrcStreamSize);
|
| 125 |
+
|
| 126 |
+
/// Add the entire MemProfData \p Incoming to the writer context.
|
| 127 |
+
bool addMemProfData(memprof::IndexedMemProfData Incoming,
|
| 128 |
+
function_ref<void(Error)> Warn);
|
| 129 |
+
|
| 130 |
+
// Add a binary id to the binary ids list.
|
| 131 |
+
void addBinaryIds(ArrayRef<llvm::object::BuildID> BIs);
|
| 132 |
+
|
| 133 |
+
void addDataAccessProfData(
|
| 134 |
+
std::unique_ptr<memprof::DataAccessProfData> DataAccessProfile);
|
| 135 |
+
|
| 136 |
+
/// Merge existing function counts from the given writer.
|
| 137 |
+
void mergeRecordsFromWriter(InstrProfWriter &&IPW,
|
| 138 |
+
function_ref<void(Error)> Warn);
|
| 139 |
+
|
| 140 |
+
/// Write the profile to \c OS
|
| 141 |
+
Error write(raw_fd_ostream &OS);
|
| 142 |
+
|
| 143 |
+
/// Write the profile to a string output stream \c OS
|
| 144 |
+
Error write(raw_string_ostream &OS);
|
| 145 |
+
|
| 146 |
+
/// Write the profile in text format to \c OS
|
| 147 |
+
Error writeText(raw_fd_ostream &OS);
|
| 148 |
+
|
| 149 |
+
/// Write temporal profile trace data to the header in text format to \c OS
|
| 150 |
+
void writeTextTemporalProfTraceData(raw_fd_ostream &OS,
|
| 151 |
+
InstrProfSymtab &Symtab);
|
| 152 |
+
|
| 153 |
+
Error validateRecord(const InstrProfRecord &Func);
|
| 154 |
+
|
| 155 |
+
/// Write \c Record in text format to \c OS
|
| 156 |
+
static void writeRecordInText(StringRef Name, uint64_t Hash,
|
| 157 |
+
const InstrProfRecord &Counters,
|
| 158 |
+
InstrProfSymtab &Symtab, raw_fd_ostream &OS);
|
| 159 |
+
|
| 160 |
+
/// Write the profile, returning the raw data. For testing.
|
| 161 |
+
std::unique_ptr<MemoryBuffer> writeBuffer();
|
| 162 |
+
|
| 163 |
+
/// Update the attributes of the current profile from the attributes
|
| 164 |
+
/// specified. An error is returned if IR and FE profiles are mixed.
|
| 165 |
+
Error mergeProfileKind(const InstrProfKind Other) {
|
| 166 |
+
// If the kind is unset, this is the first profile we are merging so just
|
| 167 |
+
// set it to the given type.
|
| 168 |
+
if (ProfileKind == InstrProfKind::Unknown) {
|
| 169 |
+
ProfileKind = Other;
|
| 170 |
+
return Error::success();
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
// Returns true if merging is should fail assuming A and B are incompatible.
|
| 174 |
+
auto testIncompatible = [&](InstrProfKind A, InstrProfKind B) {
|
| 175 |
+
return (static_cast<bool>(ProfileKind & A) &&
|
| 176 |
+
static_cast<bool>(Other & B)) ||
|
| 177 |
+
(static_cast<bool>(ProfileKind & B) &&
|
| 178 |
+
static_cast<bool>(Other & A));
|
| 179 |
+
};
|
| 180 |
+
|
| 181 |
+
// Check if the profiles are in-compatible. Clang frontend profiles can't be
|
| 182 |
+
// merged with other profile types.
|
| 183 |
+
if (static_cast<bool>(
|
| 184 |
+
(ProfileKind & InstrProfKind::FrontendInstrumentation) ^
|
| 185 |
+
(Other & InstrProfKind::FrontendInstrumentation))) {
|
| 186 |
+
return make_error<InstrProfError>(instrprof_error::unsupported_version);
|
| 187 |
+
}
|
| 188 |
+
if (testIncompatible(InstrProfKind::FunctionEntryOnly,
|
| 189 |
+
InstrProfKind::FunctionEntryInstrumentation) ||
|
| 190 |
+
testIncompatible(InstrProfKind::FunctionEntryOnly,
|
| 191 |
+
InstrProfKind::LoopEntriesInstrumentation)) {
|
| 192 |
+
return make_error<InstrProfError>(
|
| 193 |
+
instrprof_error::unsupported_version,
|
| 194 |
+
"cannot merge FunctionEntryOnly profiles and BB profiles together");
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
// Now we update the profile type with the bits that are set.
|
| 198 |
+
ProfileKind |= Other;
|
| 199 |
+
return Error::success();
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
InstrProfKind getProfileKind() const { return ProfileKind; }
|
| 203 |
+
|
| 204 |
+
bool hasSingleByteCoverage() const {
|
| 205 |
+
return static_cast<bool>(ProfileKind & InstrProfKind::SingleByteCoverage);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
// Internal interfaces for testing purpose only.
|
| 209 |
+
void setValueProfDataEndianness(llvm::endianness Endianness);
|
| 210 |
+
void setOutputSparse(bool Sparse);
|
| 211 |
+
void setMemProfVersionRequested(memprof::IndexedVersion Version) {
|
| 212 |
+
MemProfVersionRequested = Version;
|
| 213 |
+
}
|
| 214 |
+
void setMemProfFullSchema(bool Full) { MemProfFullSchema = Full; }
|
| 215 |
+
// Compute the overlap b/w this object and Other. Program level result is
|
| 216 |
+
// stored in Overlap and function level result is stored in FuncLevelOverlap.
|
| 217 |
+
void overlapRecord(NamedInstrProfRecord &&Other, OverlapStats &Overlap,
|
| 218 |
+
OverlapStats &FuncLevelOverlap,
|
| 219 |
+
const OverlapFuncFilters &FuncFilter);
|
| 220 |
+
|
| 221 |
+
private:
|
| 222 |
+
void addRecord(StringRef Name, uint64_t Hash, InstrProfRecord &&I,
|
| 223 |
+
uint64_t Weight, function_ref<void(Error)> Warn);
|
| 224 |
+
bool shouldEncodeData(const ProfilingData &PD);
|
| 225 |
+
/// Add \p Trace using reservoir sampling.
|
| 226 |
+
void addTemporalProfileTrace(TemporalProfTraceTy Trace);
|
| 227 |
+
|
| 228 |
+
/// Add a memprof record for a function identified by its \p Id.
|
| 229 |
+
void addMemProfRecord(const GlobalValue::GUID Id,
|
| 230 |
+
const memprof::IndexedMemProfRecord &Record);
|
| 231 |
+
|
| 232 |
+
/// Add a memprof frame identified by the hash of the contents of the frame in
|
| 233 |
+
/// \p FrameId.
|
| 234 |
+
bool addMemProfFrame(const memprof::FrameId, const memprof::Frame &F,
|
| 235 |
+
function_ref<void(Error)> Warn);
|
| 236 |
+
|
| 237 |
+
/// Add a call stack identified by the hash of the contents of the call stack
|
| 238 |
+
/// in \p CallStack.
|
| 239 |
+
bool addMemProfCallStack(const memprof::CallStackId CSId,
|
| 240 |
+
const llvm::SmallVector<memprof::FrameId> &CallStack,
|
| 241 |
+
function_ref<void(Error)> Warn);
|
| 242 |
+
|
| 243 |
+
Error writeImpl(ProfOStream &OS);
|
| 244 |
+
|
| 245 |
+
// Writes known header fields and reserves space for fields whose value are
|
| 246 |
+
// known only after payloads are written. Returns the start byte offset for
|
| 247 |
+
// back patching.
|
| 248 |
+
uint64_t writeHeader(const IndexedInstrProf::Header &header,
|
| 249 |
+
const bool WritePrevVersion, ProfOStream &OS);
|
| 250 |
+
|
| 251 |
+
// Writes binary IDs.
|
| 252 |
+
Error writeBinaryIds(ProfOStream &OS);
|
| 253 |
+
|
| 254 |
+
// Writes compressed vtable names to profiles.
|
| 255 |
+
Error writeVTableNames(ProfOStream &OS);
|
| 256 |
+
};
|
| 257 |
+
|
| 258 |
+
} // end namespace llvm
|
| 259 |
+
|
| 260 |
+
#endif // LLVM_PROFILEDATA_INSTRPROFWRITER_H
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/ItaniumManglingCanonicalizer.h
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===--- ItaniumManglingCanonicalizer.h -------------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file defines a class for computing equivalence classes of mangled names
|
| 10 |
+
// given a set of equivalences between name fragments.
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#ifndef LLVM_PROFILEDATA_ITANIUMMANGLINGCANONICALIZER_H
|
| 15 |
+
#define LLVM_PROFILEDATA_ITANIUMMANGLINGCANONICALIZER_H
|
| 16 |
+
|
| 17 |
+
#include <cstdint>
|
| 18 |
+
|
| 19 |
+
namespace llvm {
|
| 20 |
+
|
| 21 |
+
class StringRef;
|
| 22 |
+
|
| 23 |
+
/// Canonicalizer for mangled names.
|
| 24 |
+
///
|
| 25 |
+
/// This class allows specifying a list of "equivalent" manglings. For example,
|
| 26 |
+
/// you can specify that Ss is equivalent to
|
| 27 |
+
/// NSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE
|
| 28 |
+
/// and then manglings that refer to libstdc++'s 'std::string' will be
|
| 29 |
+
/// considered equivalent to manglings that are the same except that they refer
|
| 30 |
+
/// to libc++'s 'std::string'.
|
| 31 |
+
///
|
| 32 |
+
/// This can be used when data (eg, profiling data) is available for a version
|
| 33 |
+
/// of a program built in a different configuration, with correspondingly
|
| 34 |
+
/// different manglings.
|
| 35 |
+
class ItaniumManglingCanonicalizer {
|
| 36 |
+
public:
|
| 37 |
+
ItaniumManglingCanonicalizer();
|
| 38 |
+
ItaniumManglingCanonicalizer(const ItaniumManglingCanonicalizer &) = delete;
|
| 39 |
+
void operator=(const ItaniumManglingCanonicalizer &) = delete;
|
| 40 |
+
~ItaniumManglingCanonicalizer();
|
| 41 |
+
|
| 42 |
+
enum class EquivalenceError {
|
| 43 |
+
Success,
|
| 44 |
+
|
| 45 |
+
/// Both the equivalent manglings have already been used as components of
|
| 46 |
+
/// some other mangling we've looked at. It's too late to add this
|
| 47 |
+
/// equivalence.
|
| 48 |
+
ManglingAlreadyUsed,
|
| 49 |
+
|
| 50 |
+
/// The first equivalent mangling is invalid.
|
| 51 |
+
InvalidFirstMangling,
|
| 52 |
+
|
| 53 |
+
/// The second equivalent mangling is invalid.
|
| 54 |
+
InvalidSecondMangling,
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
enum class FragmentKind {
|
| 58 |
+
/// The mangling fragment is a <name> (or a predefined <substitution>).
|
| 59 |
+
Name,
|
| 60 |
+
/// The mangling fragment is a <type>.
|
| 61 |
+
Type,
|
| 62 |
+
/// The mangling fragment is an <encoding>.
|
| 63 |
+
Encoding,
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
/// Add an equivalence between \p First and \p Second. Both manglings must
|
| 67 |
+
/// live at least as long as the canonicalizer.
|
| 68 |
+
EquivalenceError addEquivalence(FragmentKind Kind, StringRef First,
|
| 69 |
+
StringRef Second);
|
| 70 |
+
|
| 71 |
+
using Key = uintptr_t;
|
| 72 |
+
|
| 73 |
+
/// Form a canonical key for the specified mangling. They key will be the
|
| 74 |
+
/// same for all equivalent manglings, and different for any two
|
| 75 |
+
/// non-equivalent manglings, but is otherwise unspecified.
|
| 76 |
+
///
|
| 77 |
+
/// Returns Key() if (and only if) the mangling is not a valid Itanium C++
|
| 78 |
+
/// ABI mangling.
|
| 79 |
+
///
|
| 80 |
+
/// The string denoted by Mangling must live as long as the canonicalizer.
|
| 81 |
+
Key canonicalize(StringRef Mangling);
|
| 82 |
+
|
| 83 |
+
/// Find a canonical key for the specified mangling, if one has already been
|
| 84 |
+
/// formed. Otherwise returns Key().
|
| 85 |
+
Key lookup(StringRef Mangling);
|
| 86 |
+
|
| 87 |
+
private:
|
| 88 |
+
struct Impl;
|
| 89 |
+
Impl *P;
|
| 90 |
+
};
|
| 91 |
+
} // namespace llvm
|
| 92 |
+
|
| 93 |
+
#endif // LLVM_PROFILEDATA_ITANIUMMANGLINGCANONICALIZER_H
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/MIBEntryDef.inc
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*===-- MemEntryDef.inc - MemProf profiling runtime macros -*- C++ -*-======== *\
|
| 2 |
+
|*
|
| 3 |
+
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
|* See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
|*
|
| 7 |
+
\*===----------------------------------------------------------------------===*/
|
| 8 |
+
/*
|
| 9 |
+
* This file defines the macros for memprof profiling data structures.
|
| 10 |
+
* Eg. usage to define the memprof meminfoblock struct:
|
| 11 |
+
*
|
| 12 |
+
* struct MemInfoBlock {
|
| 13 |
+
* #define MIBEntryDef(NameTag, Name, Type) Type Name;
|
| 14 |
+
* #include MIBEntryDef.inc
|
| 15 |
+
* #undef MIBEntryDef
|
| 16 |
+
* };
|
| 17 |
+
*
|
| 18 |
+
* This file has two identical copies. The primary copy lives in LLVM and
|
| 19 |
+
* the other one sits in compiler-rt/include/profile directory. To make changes
|
| 20 |
+
* in this file, first modify the primary copy and copy it over to compiler-rt.
|
| 21 |
+
* Testing of any change in this file can start only after the two copies are
|
| 22 |
+
* synced up.
|
| 23 |
+
*
|
| 24 |
+
\*===----------------------------------------------------------------------===*/
|
| 25 |
+
#ifndef MIBEntryDef
|
| 26 |
+
#define MIBEntryDef(NameTag, Name, Type)
|
| 27 |
+
#endif
|
| 28 |
+
|
| 29 |
+
MIBEntryDef(AllocCount = 1, AllocCount, uint32_t)
|
| 30 |
+
MIBEntryDef(TotalAccessCount = 2, TotalAccessCount, uint64_t)
|
| 31 |
+
MIBEntryDef(MinAccessCount = 3, MinAccessCount, uint64_t)
|
| 32 |
+
MIBEntryDef(MaxAccessCount = 4, MaxAccessCount, uint64_t)
|
| 33 |
+
MIBEntryDef(TotalSize = 5, TotalSize, uint64_t)
|
| 34 |
+
MIBEntryDef(MinSize = 6, MinSize, uint32_t)
|
| 35 |
+
MIBEntryDef(MaxSize = 7, MaxSize, uint32_t)
|
| 36 |
+
MIBEntryDef(AllocTimestamp = 8, AllocTimestamp, uint32_t)
|
| 37 |
+
MIBEntryDef(DeallocTimestamp = 9, DeallocTimestamp, uint32_t)
|
| 38 |
+
MIBEntryDef(TotalLifetime = 10, TotalLifetime, uint64_t)
|
| 39 |
+
MIBEntryDef(MinLifetime = 11, MinLifetime, uint32_t)
|
| 40 |
+
MIBEntryDef(MaxLifetime = 12, MaxLifetime, uint32_t)
|
| 41 |
+
MIBEntryDef(AllocCpuId = 13, AllocCpuId, uint32_t)
|
| 42 |
+
MIBEntryDef(DeallocCpuId = 14, DeallocCpuId, uint32_t)
|
| 43 |
+
MIBEntryDef(NumMigratedCpu = 15, NumMigratedCpu, uint32_t)
|
| 44 |
+
MIBEntryDef(NumLifetimeOverlaps = 16, NumLifetimeOverlaps, uint32_t)
|
| 45 |
+
MIBEntryDef(NumSameAllocCpu = 17, NumSameAllocCpu, uint32_t)
|
| 46 |
+
MIBEntryDef(NumSameDeallocCpu = 18, NumSameDeallocCpu, uint32_t)
|
| 47 |
+
MIBEntryDef(DataTypeId = 19, DataTypeId, uint64_t)
|
| 48 |
+
MIBEntryDef(TotalAccessDensity = 20, TotalAccessDensity, uint64_t)
|
| 49 |
+
MIBEntryDef(MinAccessDensity = 21, MinAccessDensity, uint32_t)
|
| 50 |
+
MIBEntryDef(MaxAccessDensity = 22, MaxAccessDensity, uint32_t)
|
| 51 |
+
MIBEntryDef(TotalLifetimeAccessDensity = 23, TotalLifetimeAccessDensity, uint64_t)
|
| 52 |
+
MIBEntryDef(MinLifetimeAccessDensity = 24, MinLifetimeAccessDensity, uint32_t)
|
| 53 |
+
MIBEntryDef(MaxLifetimeAccessDensity = 25, MaxLifetimeAccessDensity, uint32_t)
|
| 54 |
+
MIBEntryDef(AccessHistogramSize = 26, AccessHistogramSize, uint32_t)
|
| 55 |
+
MIBEntryDef(AccessHistogram = 27, AccessHistogram, uintptr_t)
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/MemProf.h
ADDED
|
@@ -0,0 +1,859 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- MemProf.h - MemProf support ------------------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file contains common definitions used in the reading and writing of
|
| 10 |
+
// memory profile data.
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#ifndef LLVM_PROFILEDATA_MEMPROF_H
|
| 15 |
+
#define LLVM_PROFILEDATA_MEMPROF_H
|
| 16 |
+
|
| 17 |
+
#include "llvm/ADT/BitVector.h"
|
| 18 |
+
#include "llvm/ADT/MapVector.h"
|
| 19 |
+
#include "llvm/ADT/STLForwardCompat.h"
|
| 20 |
+
#include "llvm/ADT/STLFunctionalExtras.h"
|
| 21 |
+
#include "llvm/ADT/SmallVector.h"
|
| 22 |
+
#include "llvm/ADT/StringRef.h"
|
| 23 |
+
#include "llvm/IR/GlobalValue.h"
|
| 24 |
+
#include "llvm/ProfileData/MemProfData.inc"
|
| 25 |
+
#include "llvm/Support/BLAKE3.h"
|
| 26 |
+
#include "llvm/Support/Endian.h"
|
| 27 |
+
#include "llvm/Support/EndianStream.h"
|
| 28 |
+
#include "llvm/Support/HashBuilder.h"
|
| 29 |
+
#include "llvm/Support/raw_ostream.h"
|
| 30 |
+
|
| 31 |
+
#include <bitset>
|
| 32 |
+
#include <cstdint>
|
| 33 |
+
#include <optional>
|
| 34 |
+
|
| 35 |
+
namespace llvm {
|
| 36 |
+
namespace yaml {
|
| 37 |
+
template <typename T> struct CustomMappingTraits;
|
| 38 |
+
} // namespace yaml
|
| 39 |
+
|
| 40 |
+
namespace memprof {
|
| 41 |
+
|
| 42 |
+
struct MemProfRecord;
|
| 43 |
+
|
| 44 |
+
// The versions of the indexed MemProf format
|
| 45 |
+
enum IndexedVersion : uint64_t {
|
| 46 |
+
// Version 2: Added a call stack table.
|
| 47 |
+
Version2 = 2,
|
| 48 |
+
// Version 3: Added a radix tree for call stacks. Switched to linear IDs for
|
| 49 |
+
// frames and call stacks.
|
| 50 |
+
Version3 = 3,
|
| 51 |
+
// Version 4: Added CalleeGuids to call site info.
|
| 52 |
+
Version4 = 4,
|
| 53 |
+
};
|
| 54 |
+
|
| 55 |
+
constexpr uint64_t MinimumSupportedVersion = Version2;
|
| 56 |
+
constexpr uint64_t MaximumSupportedVersion = Version4;
|
| 57 |
+
|
| 58 |
+
// Verify that the minimum and maximum satisfy the obvious constraint.
|
| 59 |
+
static_assert(MinimumSupportedVersion <= MaximumSupportedVersion);
|
| 60 |
+
|
| 61 |
+
inline llvm::StringRef getMemprofOptionsSymbolDarwinLinkageName() {
|
| 62 |
+
return "___memprof_default_options_str";
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
inline llvm::StringRef getMemprofOptionsSymbolName() {
|
| 66 |
+
// Darwin linkage names are prefixed with an extra "_". See
|
| 67 |
+
// DataLayout::getGlobalPrefix().
|
| 68 |
+
return getMemprofOptionsSymbolDarwinLinkageName().drop_front();
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
enum class Meta : uint64_t {
|
| 72 |
+
Start = 0,
|
| 73 |
+
#define MIBEntryDef(NameTag, Name, Type) NameTag,
|
| 74 |
+
#include "llvm/ProfileData/MIBEntryDef.inc"
|
| 75 |
+
#undef MIBEntryDef
|
| 76 |
+
Size
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
using MemProfSchema = llvm::SmallVector<Meta, static_cast<int>(Meta::Size)>;
|
| 80 |
+
|
| 81 |
+
// Returns the full schema currently in use.
|
| 82 |
+
MemProfSchema getFullSchema();
|
| 83 |
+
|
| 84 |
+
// Returns the schema consisting of the fields used for hot cold memory hinting.
|
| 85 |
+
MemProfSchema getHotColdSchema();
|
| 86 |
+
|
| 87 |
+
// Holds the actual MemInfoBlock data with all fields. Contents may be read or
|
| 88 |
+
// written partially by providing an appropriate schema to the serialize and
|
| 89 |
+
// deserialize methods.
|
| 90 |
+
struct PortableMemInfoBlock {
|
| 91 |
+
PortableMemInfoBlock() = default;
|
| 92 |
+
explicit PortableMemInfoBlock(const MemInfoBlock &Block,
|
| 93 |
+
const MemProfSchema &IncomingSchema) {
|
| 94 |
+
for (const Meta Id : IncomingSchema)
|
| 95 |
+
Schema.set(llvm::to_underlying(Id));
|
| 96 |
+
#define MIBEntryDef(NameTag, Name, Type) Name = Block.Name;
|
| 97 |
+
#include "llvm/ProfileData/MIBEntryDef.inc"
|
| 98 |
+
#undef MIBEntryDef
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
PortableMemInfoBlock(const MemProfSchema &Schema, const unsigned char *Ptr) {
|
| 102 |
+
deserialize(Schema, Ptr);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
// Read the contents of \p Ptr based on the \p Schema to populate the
|
| 106 |
+
// MemInfoBlock member.
|
| 107 |
+
void deserialize(const MemProfSchema &IncomingSchema,
|
| 108 |
+
const unsigned char *Ptr) {
|
| 109 |
+
using namespace support;
|
| 110 |
+
|
| 111 |
+
Schema.reset();
|
| 112 |
+
for (const Meta Id : IncomingSchema) {
|
| 113 |
+
switch (Id) {
|
| 114 |
+
#define MIBEntryDef(NameTag, Name, Type) \
|
| 115 |
+
case Meta::Name: { \
|
| 116 |
+
Name = endian::readNext<Type, llvm::endianness::little>(Ptr); \
|
| 117 |
+
} break;
|
| 118 |
+
#include "llvm/ProfileData/MIBEntryDef.inc"
|
| 119 |
+
#undef MIBEntryDef
|
| 120 |
+
default:
|
| 121 |
+
llvm_unreachable("Unknown meta type id, is the profile collected from "
|
| 122 |
+
"a newer version of the runtime?");
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
Schema.set(llvm::to_underlying(Id));
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
// Write the contents of the MemInfoBlock based on the \p Schema provided to
|
| 130 |
+
// the raw_ostream \p OS.
|
| 131 |
+
void serialize(const MemProfSchema &Schema, raw_ostream &OS) const {
|
| 132 |
+
using namespace support;
|
| 133 |
+
|
| 134 |
+
endian::Writer LE(OS, llvm::endianness::little);
|
| 135 |
+
for (const Meta Id : Schema) {
|
| 136 |
+
switch (Id) {
|
| 137 |
+
#define MIBEntryDef(NameTag, Name, Type) \
|
| 138 |
+
case Meta::Name: { \
|
| 139 |
+
LE.write<Type>(Name); \
|
| 140 |
+
} break;
|
| 141 |
+
#include "llvm/ProfileData/MIBEntryDef.inc"
|
| 142 |
+
#undef MIBEntryDef
|
| 143 |
+
default:
|
| 144 |
+
llvm_unreachable("Unknown meta type id, invalid input?");
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
// Print out the contents of the MemInfoBlock in YAML format.
|
| 150 |
+
void printYAML(raw_ostream &OS) const {
|
| 151 |
+
OS << " MemInfoBlock:\n";
|
| 152 |
+
#define MIBEntryDef(NameTag, Name, Type) \
|
| 153 |
+
OS << " " << #Name << ": " << Name << "\n";
|
| 154 |
+
#include "llvm/ProfileData/MIBEntryDef.inc"
|
| 155 |
+
#undef MIBEntryDef
|
| 156 |
+
if (AccessHistogramSize > 0) {
|
| 157 |
+
OS << " " << "AccessHistogramValues" << ":";
|
| 158 |
+
for (uint32_t I = 0; I < AccessHistogramSize; ++I) {
|
| 159 |
+
OS << " " << ((uint64_t *)AccessHistogram)[I];
|
| 160 |
+
}
|
| 161 |
+
OS << "\n";
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
// Return the schema, only for unit tests.
|
| 166 |
+
std::bitset<llvm::to_underlying(Meta::Size)> getSchema() const {
|
| 167 |
+
return Schema;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
// Define getters for each type which can be called by analyses.
|
| 171 |
+
#define MIBEntryDef(NameTag, Name, Type) \
|
| 172 |
+
Type get##Name() const { \
|
| 173 |
+
assert(Schema[llvm::to_underlying(Meta::Name)]); \
|
| 174 |
+
return Name; \
|
| 175 |
+
}
|
| 176 |
+
#include "llvm/ProfileData/MIBEntryDef.inc"
|
| 177 |
+
#undef MIBEntryDef
|
| 178 |
+
|
| 179 |
+
// Define setters for each type which can be called by the writer.
|
| 180 |
+
#define MIBEntryDef(NameTag, Name, Type) \
|
| 181 |
+
void set##Name(Type NewVal) { \
|
| 182 |
+
assert(Schema[llvm::to_underlying(Meta::Name)]); \
|
| 183 |
+
Name = NewVal; \
|
| 184 |
+
}
|
| 185 |
+
#include "llvm/ProfileData/MIBEntryDef.inc"
|
| 186 |
+
#undef MIBEntryDef
|
| 187 |
+
|
| 188 |
+
void clear() { *this = PortableMemInfoBlock(); }
|
| 189 |
+
|
| 190 |
+
bool operator==(const PortableMemInfoBlock &Other) const {
|
| 191 |
+
if (Other.Schema != Schema)
|
| 192 |
+
return false;
|
| 193 |
+
|
| 194 |
+
#define MIBEntryDef(NameTag, Name, Type) \
|
| 195 |
+
if (Schema[llvm::to_underlying(Meta::Name)] && \
|
| 196 |
+
Other.get##Name() != get##Name()) \
|
| 197 |
+
return false;
|
| 198 |
+
#include "llvm/ProfileData/MIBEntryDef.inc"
|
| 199 |
+
#undef MIBEntryDef
|
| 200 |
+
return true;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
bool operator!=(const PortableMemInfoBlock &Other) const {
|
| 204 |
+
return !operator==(Other);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
static size_t serializedSize(const MemProfSchema &Schema) {
|
| 208 |
+
size_t Result = 0;
|
| 209 |
+
|
| 210 |
+
for (const Meta Id : Schema) {
|
| 211 |
+
switch (Id) {
|
| 212 |
+
#define MIBEntryDef(NameTag, Name, Type) \
|
| 213 |
+
case Meta::Name: { \
|
| 214 |
+
Result += sizeof(Type); \
|
| 215 |
+
} break;
|
| 216 |
+
#include "llvm/ProfileData/MIBEntryDef.inc"
|
| 217 |
+
#undef MIBEntryDef
|
| 218 |
+
default:
|
| 219 |
+
llvm_unreachable("Unknown meta type id, invalid input?");
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
return Result;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
// Give YAML access to the individual MIB fields.
|
| 227 |
+
friend struct yaml::CustomMappingTraits<memprof::PortableMemInfoBlock>;
|
| 228 |
+
|
| 229 |
+
private:
|
| 230 |
+
// The set of available fields, indexed by Meta::Name.
|
| 231 |
+
std::bitset<llvm::to_underlying(Meta::Size)> Schema;
|
| 232 |
+
|
| 233 |
+
#define MIBEntryDef(NameTag, Name, Type) Type Name = Type();
|
| 234 |
+
#include "llvm/ProfileData/MIBEntryDef.inc"
|
| 235 |
+
#undef MIBEntryDef
|
| 236 |
+
};
|
| 237 |
+
|
| 238 |
+
// A type representing the id generated by hashing the contents of the Frame.
|
| 239 |
+
using FrameId = uint64_t;
|
| 240 |
+
// A type representing the id to index into the frame array.
|
| 241 |
+
using LinearFrameId = uint32_t;
|
| 242 |
+
// Describes a call frame for a dynamic allocation context. The contents of
|
| 243 |
+
// the frame are populated by symbolizing the stack depot call frame from the
|
| 244 |
+
// compiler runtime.
|
| 245 |
+
struct Frame {
|
| 246 |
+
// A uuid (uint64_t) identifying the function. It is obtained by
|
| 247 |
+
// llvm::md5(FunctionName) which returns the lower 64 bits.
|
| 248 |
+
GlobalValue::GUID Function = 0;
|
| 249 |
+
// The symbol name for the function. Only populated in the Frame by the reader
|
| 250 |
+
// if requested during initialization. This field should not be serialized.
|
| 251 |
+
std::unique_ptr<std::string> SymbolName;
|
| 252 |
+
// The source line offset of the call from the beginning of parent function.
|
| 253 |
+
uint32_t LineOffset = 0;
|
| 254 |
+
// The source column number of the call to help distinguish multiple calls
|
| 255 |
+
// on the same line.
|
| 256 |
+
uint32_t Column = 0;
|
| 257 |
+
// Whether the current frame is inlined.
|
| 258 |
+
bool IsInlineFrame = false;
|
| 259 |
+
|
| 260 |
+
Frame() = default;
|
| 261 |
+
Frame(const Frame &Other) {
|
| 262 |
+
Function = Other.Function;
|
| 263 |
+
SymbolName = Other.SymbolName
|
| 264 |
+
? std::make_unique<std::string>(*Other.SymbolName)
|
| 265 |
+
: nullptr;
|
| 266 |
+
LineOffset = Other.LineOffset;
|
| 267 |
+
Column = Other.Column;
|
| 268 |
+
IsInlineFrame = Other.IsInlineFrame;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
Frame(GlobalValue::GUID Hash, uint32_t Off, uint32_t Col, bool Inline)
|
| 272 |
+
: Function(Hash), LineOffset(Off), Column(Col), IsInlineFrame(Inline) {}
|
| 273 |
+
|
| 274 |
+
bool operator==(const Frame &Other) const {
|
| 275 |
+
// Ignore the SymbolName field to avoid a string compare. Comparing the
|
| 276 |
+
// function hash serves the same purpose.
|
| 277 |
+
return Other.Function == Function && Other.LineOffset == LineOffset &&
|
| 278 |
+
Other.Column == Column && Other.IsInlineFrame == IsInlineFrame;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
Frame &operator=(const Frame &Other) {
|
| 282 |
+
Function = Other.Function;
|
| 283 |
+
SymbolName = Other.SymbolName
|
| 284 |
+
? std::make_unique<std::string>(*Other.SymbolName)
|
| 285 |
+
: nullptr;
|
| 286 |
+
LineOffset = Other.LineOffset;
|
| 287 |
+
Column = Other.Column;
|
| 288 |
+
IsInlineFrame = Other.IsInlineFrame;
|
| 289 |
+
return *this;
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
bool operator!=(const Frame &Other) const { return !operator==(Other); }
|
| 293 |
+
|
| 294 |
+
bool hasSymbolName() const { return !!SymbolName; }
|
| 295 |
+
|
| 296 |
+
StringRef getSymbolName() const {
|
| 297 |
+
assert(hasSymbolName());
|
| 298 |
+
return *SymbolName;
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
std::string getSymbolNameOr(StringRef Alt) const {
|
| 302 |
+
return std::string(hasSymbolName() ? getSymbolName() : Alt);
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
// Write the contents of the frame to the ostream \p OS.
|
| 306 |
+
void serialize(raw_ostream &OS) const {
|
| 307 |
+
using namespace support;
|
| 308 |
+
|
| 309 |
+
endian::Writer LE(OS, llvm::endianness::little);
|
| 310 |
+
|
| 311 |
+
// If the type of the GlobalValue::GUID changes, then we need to update
|
| 312 |
+
// the reader and the writer.
|
| 313 |
+
static_assert(std::is_same<GlobalValue::GUID, uint64_t>::value,
|
| 314 |
+
"Expect GUID to be uint64_t.");
|
| 315 |
+
LE.write<uint64_t>(Function);
|
| 316 |
+
|
| 317 |
+
LE.write<uint32_t>(LineOffset);
|
| 318 |
+
LE.write<uint32_t>(Column);
|
| 319 |
+
LE.write<bool>(IsInlineFrame);
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
// Read a frame from char data which has been serialized as little endian.
|
| 323 |
+
static Frame deserialize(const unsigned char *Ptr) {
|
| 324 |
+
using namespace support;
|
| 325 |
+
|
| 326 |
+
const uint64_t F =
|
| 327 |
+
endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
|
| 328 |
+
const uint32_t L =
|
| 329 |
+
endian::readNext<uint32_t, llvm::endianness::little>(Ptr);
|
| 330 |
+
const uint32_t C =
|
| 331 |
+
endian::readNext<uint32_t, llvm::endianness::little>(Ptr);
|
| 332 |
+
const bool I = endian::readNext<bool, llvm::endianness::little>(Ptr);
|
| 333 |
+
return Frame(/*Function=*/F, /*LineOffset=*/L, /*Column=*/C,
|
| 334 |
+
/*IsInlineFrame=*/I);
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
// Returns the size of the frame information.
|
| 338 |
+
static constexpr size_t serializedSize() {
|
| 339 |
+
return sizeof(Frame::Function) + sizeof(Frame::LineOffset) +
|
| 340 |
+
sizeof(Frame::Column) + sizeof(Frame::IsInlineFrame);
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
// Print the frame information in YAML format.
|
| 344 |
+
void printYAML(raw_ostream &OS) const {
|
| 345 |
+
OS << " -\n"
|
| 346 |
+
<< " Function: " << Function << "\n"
|
| 347 |
+
<< " SymbolName: " << getSymbolNameOr("<None>") << "\n"
|
| 348 |
+
<< " LineOffset: " << LineOffset << "\n"
|
| 349 |
+
<< " Column: " << Column << "\n"
|
| 350 |
+
<< " Inline: " << IsInlineFrame << "\n";
|
| 351 |
+
}
|
| 352 |
+
};
|
| 353 |
+
|
| 354 |
+
// A type representing the index into the table of call stacks.
|
| 355 |
+
using CallStackId = uint64_t;
|
| 356 |
+
|
| 357 |
+
// A type representing the index into the call stack array.
|
| 358 |
+
using LinearCallStackId = uint32_t;
|
| 359 |
+
|
| 360 |
+
// Holds call site information with indexed frame contents.
|
| 361 |
+
struct IndexedCallSiteInfo {
|
| 362 |
+
// The call stack ID for this call site
|
| 363 |
+
CallStackId CSId = 0;
|
| 364 |
+
// The GUIDs of the callees at this call site
|
| 365 |
+
SmallVector<GlobalValue::GUID, 1> CalleeGuids;
|
| 366 |
+
|
| 367 |
+
IndexedCallSiteInfo() = default;
|
| 368 |
+
IndexedCallSiteInfo(CallStackId CSId) : CSId(CSId) {}
|
| 369 |
+
IndexedCallSiteInfo(CallStackId CSId,
|
| 370 |
+
SmallVector<GlobalValue::GUID, 1> CalleeGuids)
|
| 371 |
+
: CSId(CSId), CalleeGuids(std::move(CalleeGuids)) {}
|
| 372 |
+
|
| 373 |
+
bool operator==(const IndexedCallSiteInfo &Other) const {
|
| 374 |
+
return CSId == Other.CSId && CalleeGuids == Other.CalleeGuids;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
bool operator!=(const IndexedCallSiteInfo &Other) const {
|
| 378 |
+
return !operator==(Other);
|
| 379 |
+
}
|
| 380 |
+
};
|
| 381 |
+
|
| 382 |
+
// Holds allocation information in a space efficient format where frames are
|
| 383 |
+
// represented using unique identifiers.
|
| 384 |
+
struct IndexedAllocationInfo {
|
| 385 |
+
// The dynamic calling context for the allocation in bottom-up (leaf-to-root)
|
| 386 |
+
// order. Frame contents are stored out-of-line.
|
| 387 |
+
CallStackId CSId = 0;
|
| 388 |
+
// The statistics obtained from the runtime for the allocation.
|
| 389 |
+
PortableMemInfoBlock Info;
|
| 390 |
+
|
| 391 |
+
IndexedAllocationInfo() = default;
|
| 392 |
+
IndexedAllocationInfo(CallStackId CSId, const MemInfoBlock &MB,
|
| 393 |
+
const MemProfSchema &Schema = getFullSchema())
|
| 394 |
+
: CSId(CSId), Info(MB, Schema) {}
|
| 395 |
+
IndexedAllocationInfo(CallStackId CSId, const PortableMemInfoBlock &MB)
|
| 396 |
+
: CSId(CSId), Info(MB) {}
|
| 397 |
+
|
| 398 |
+
// Returns the size in bytes when this allocation info struct is serialized.
|
| 399 |
+
size_t serializedSize(const MemProfSchema &Schema,
|
| 400 |
+
IndexedVersion Version) const;
|
| 401 |
+
|
| 402 |
+
bool operator==(const IndexedAllocationInfo &Other) const {
|
| 403 |
+
if (Other.Info != Info)
|
| 404 |
+
return false;
|
| 405 |
+
|
| 406 |
+
if (Other.CSId != CSId)
|
| 407 |
+
return false;
|
| 408 |
+
return true;
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
bool operator!=(const IndexedAllocationInfo &Other) const {
|
| 412 |
+
return !operator==(Other);
|
| 413 |
+
}
|
| 414 |
+
};
|
| 415 |
+
|
| 416 |
+
// Holds allocation information with frame contents inline. The type should
|
| 417 |
+
// be used for temporary in-memory instances.
|
| 418 |
+
struct AllocationInfo {
|
| 419 |
+
// Same as IndexedAllocationInfo::CallStack with the frame contents inline.
|
| 420 |
+
std::vector<Frame> CallStack;
|
| 421 |
+
// Same as IndexedAllocationInfo::Info;
|
| 422 |
+
PortableMemInfoBlock Info;
|
| 423 |
+
|
| 424 |
+
AllocationInfo() = default;
|
| 425 |
+
|
| 426 |
+
void printYAML(raw_ostream &OS) const {
|
| 427 |
+
OS << " -\n";
|
| 428 |
+
OS << " Callstack:\n";
|
| 429 |
+
// TODO: Print out the frame on one line with to make it easier for deep
|
| 430 |
+
// callstacks once we have a test to check valid YAML is generated.
|
| 431 |
+
for (const Frame &F : CallStack) {
|
| 432 |
+
F.printYAML(OS);
|
| 433 |
+
}
|
| 434 |
+
Info.printYAML(OS);
|
| 435 |
+
}
|
| 436 |
+
};
|
| 437 |
+
|
| 438 |
+
// Holds the memprof profile information for a function. The internal
|
| 439 |
+
// representation stores frame ids for efficiency. This representation should
|
| 440 |
+
// be used in the profile conversion and manipulation tools.
|
| 441 |
+
struct IndexedMemProfRecord {
|
| 442 |
+
// Memory allocation sites in this function for which we have memory
|
| 443 |
+
// profiling data.
|
| 444 |
+
llvm::SmallVector<IndexedAllocationInfo> AllocSites;
|
| 445 |
+
// Holds call sites in this function which are part of some memory
|
| 446 |
+
// allocation context. We store this as a list of locations, each with its
|
| 447 |
+
// list of inline locations in bottom-up order i.e. from leaf to root. The
|
| 448 |
+
// inline location list may include additional entries, users should pick
|
| 449 |
+
// the last entry in the list with the same function GUID.
|
| 450 |
+
llvm::SmallVector<IndexedCallSiteInfo> CallSites;
|
| 451 |
+
|
| 452 |
+
void clear() { *this = IndexedMemProfRecord(); }
|
| 453 |
+
|
| 454 |
+
void merge(const IndexedMemProfRecord &Other) {
|
| 455 |
+
// TODO: Filter out duplicates which may occur if multiple memprof
|
| 456 |
+
// profiles are merged together using llvm-profdata.
|
| 457 |
+
AllocSites.append(Other.AllocSites);
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
size_t serializedSize(const MemProfSchema &Schema,
|
| 461 |
+
IndexedVersion Version) const;
|
| 462 |
+
|
| 463 |
+
bool operator==(const IndexedMemProfRecord &Other) const {
|
| 464 |
+
if (Other.AllocSites != AllocSites)
|
| 465 |
+
return false;
|
| 466 |
+
|
| 467 |
+
if (Other.CallSites != CallSites)
|
| 468 |
+
return false;
|
| 469 |
+
return true;
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
// Serializes the memprof records in \p Records to the ostream \p OS based
|
| 473 |
+
// on the schema provided in \p Schema.
|
| 474 |
+
void serialize(const MemProfSchema &Schema, raw_ostream &OS,
|
| 475 |
+
IndexedVersion Version,
|
| 476 |
+
llvm::DenseMap<CallStackId, LinearCallStackId>
|
| 477 |
+
*MemProfCallStackIndexes = nullptr) const;
|
| 478 |
+
|
| 479 |
+
// Deserializes memprof records from the Buffer.
|
| 480 |
+
static IndexedMemProfRecord deserialize(const MemProfSchema &Schema,
|
| 481 |
+
const unsigned char *Buffer,
|
| 482 |
+
IndexedVersion Version);
|
| 483 |
+
|
| 484 |
+
// Convert IndexedMemProfRecord to MemProfRecord. Callback is used to
|
| 485 |
+
// translate CallStackId to call stacks with frames inline.
|
| 486 |
+
MemProfRecord toMemProfRecord(
|
| 487 |
+
llvm::function_ref<std::vector<Frame>(const CallStackId)> Callback) const;
|
| 488 |
+
};
|
| 489 |
+
|
| 490 |
+
// Returns the GUID for the function name after canonicalization. For
|
| 491 |
+
// memprof, we remove any .llvm suffix added by LTO. MemProfRecords are
|
| 492 |
+
// mapped to functions using this GUID.
|
| 493 |
+
GlobalValue::GUID getGUID(const StringRef FunctionName);
|
| 494 |
+
|
| 495 |
+
// Holds call site information with frame contents inline.
|
| 496 |
+
struct CallSiteInfo {
|
| 497 |
+
// The frames in the call stack
|
| 498 |
+
std::vector<Frame> Frames;
|
| 499 |
+
|
| 500 |
+
// The GUIDs of the callees at this call site
|
| 501 |
+
SmallVector<GlobalValue::GUID, 1> CalleeGuids;
|
| 502 |
+
|
| 503 |
+
CallSiteInfo() = default;
|
| 504 |
+
CallSiteInfo(std::vector<Frame> Frames) : Frames(std::move(Frames)) {}
|
| 505 |
+
CallSiteInfo(std::vector<Frame> Frames,
|
| 506 |
+
SmallVector<GlobalValue::GUID, 1> CalleeGuids)
|
| 507 |
+
: Frames(std::move(Frames)), CalleeGuids(std::move(CalleeGuids)) {}
|
| 508 |
+
|
| 509 |
+
bool operator==(const CallSiteInfo &Other) const {
|
| 510 |
+
return Frames == Other.Frames && CalleeGuids == Other.CalleeGuids;
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
bool operator!=(const CallSiteInfo &Other) const {
|
| 514 |
+
return !operator==(Other);
|
| 515 |
+
}
|
| 516 |
+
};
|
| 517 |
+
|
| 518 |
+
// Holds the memprof profile information for a function. The internal
|
| 519 |
+
// representation stores frame contents inline. This representation should
|
| 520 |
+
// be used for small amount of temporary, in memory instances.
|
| 521 |
+
struct MemProfRecord {
|
| 522 |
+
// Same as IndexedMemProfRecord::AllocSites with frame contents inline.
|
| 523 |
+
llvm::SmallVector<AllocationInfo> AllocSites;
|
| 524 |
+
// Same as IndexedMemProfRecord::CallSites with frame contents inline.
|
| 525 |
+
llvm::SmallVector<CallSiteInfo> CallSites;
|
| 526 |
+
|
| 527 |
+
MemProfRecord() = default;
|
| 528 |
+
|
| 529 |
+
// Prints out the contents of the memprof record in YAML.
|
| 530 |
+
void print(llvm::raw_ostream &OS) const {
|
| 531 |
+
if (!AllocSites.empty()) {
|
| 532 |
+
OS << " AllocSites:\n";
|
| 533 |
+
for (const AllocationInfo &N : AllocSites)
|
| 534 |
+
N.printYAML(OS);
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
if (!CallSites.empty()) {
|
| 538 |
+
OS << " CallSites:\n";
|
| 539 |
+
for (const CallSiteInfo &CS : CallSites) {
|
| 540 |
+
for (const Frame &F : CS.Frames) {
|
| 541 |
+
OS << " -\n";
|
| 542 |
+
F.printYAML(OS);
|
| 543 |
+
}
|
| 544 |
+
}
|
| 545 |
+
}
|
| 546 |
+
}
|
| 547 |
+
};
|
| 548 |
+
|
| 549 |
+
// Reads a memprof schema from a buffer. All entries in the buffer are
|
| 550 |
+
// interpreted as uint64_t. The first entry in the buffer denotes the number of
|
| 551 |
+
// ids in the schema. Subsequent entries are integers which map to memprof::Meta
|
| 552 |
+
// enum class entries. After successfully reading the schema, the pointer is one
|
| 553 |
+
// byte past the schema contents.
|
| 554 |
+
Expected<MemProfSchema> readMemProfSchema(const unsigned char *&Buffer);
|
| 555 |
+
|
| 556 |
+
// Trait for reading IndexedMemProfRecord data from the on-disk hash table.
|
| 557 |
+
class RecordLookupTrait {
|
| 558 |
+
public:
|
| 559 |
+
using data_type = const IndexedMemProfRecord &;
|
| 560 |
+
using internal_key_type = uint64_t;
|
| 561 |
+
using external_key_type = uint64_t;
|
| 562 |
+
using hash_value_type = uint64_t;
|
| 563 |
+
using offset_type = uint64_t;
|
| 564 |
+
|
| 565 |
+
RecordLookupTrait() = delete;
|
| 566 |
+
RecordLookupTrait(IndexedVersion V, const MemProfSchema &S)
|
| 567 |
+
: Version(V), Schema(S) {}
|
| 568 |
+
|
| 569 |
+
static bool EqualKey(uint64_t A, uint64_t B) { return A == B; }
|
| 570 |
+
static uint64_t GetInternalKey(uint64_t K) { return K; }
|
| 571 |
+
static uint64_t GetExternalKey(uint64_t K) { return K; }
|
| 572 |
+
|
| 573 |
+
hash_value_type ComputeHash(uint64_t K) { return K; }
|
| 574 |
+
|
| 575 |
+
static std::pair<offset_type, offset_type>
|
| 576 |
+
ReadKeyDataLength(const unsigned char *&D) {
|
| 577 |
+
using namespace support;
|
| 578 |
+
|
| 579 |
+
offset_type KeyLen =
|
| 580 |
+
endian::readNext<offset_type, llvm::endianness::little>(D);
|
| 581 |
+
offset_type DataLen =
|
| 582 |
+
endian::readNext<offset_type, llvm::endianness::little>(D);
|
| 583 |
+
return std::make_pair(KeyLen, DataLen);
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
uint64_t ReadKey(const unsigned char *D, offset_type /*Unused*/) {
|
| 587 |
+
using namespace support;
|
| 588 |
+
return endian::readNext<external_key_type, llvm::endianness::little>(D);
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
data_type ReadData(uint64_t K, const unsigned char *D,
|
| 592 |
+
offset_type /*Unused*/) {
|
| 593 |
+
Record = IndexedMemProfRecord::deserialize(Schema, D, Version);
|
| 594 |
+
return Record;
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
private:
|
| 598 |
+
// Holds the MemProf version.
|
| 599 |
+
IndexedVersion Version;
|
| 600 |
+
// Holds the memprof schema used to deserialize records.
|
| 601 |
+
MemProfSchema Schema;
|
| 602 |
+
// Holds the records from one function deserialized from the indexed format.
|
| 603 |
+
IndexedMemProfRecord Record;
|
| 604 |
+
};
|
| 605 |
+
|
| 606 |
+
// Trait for writing IndexedMemProfRecord data to the on-disk hash table.
|
| 607 |
+
class RecordWriterTrait {
|
| 608 |
+
public:
|
| 609 |
+
using key_type = uint64_t;
|
| 610 |
+
using key_type_ref = uint64_t;
|
| 611 |
+
|
| 612 |
+
using data_type = IndexedMemProfRecord;
|
| 613 |
+
using data_type_ref = IndexedMemProfRecord &;
|
| 614 |
+
|
| 615 |
+
using hash_value_type = uint64_t;
|
| 616 |
+
using offset_type = uint64_t;
|
| 617 |
+
|
| 618 |
+
private:
|
| 619 |
+
// Pointer to the memprof schema to use for the generator.
|
| 620 |
+
const MemProfSchema *Schema;
|
| 621 |
+
// The MemProf version to use for the serialization.
|
| 622 |
+
IndexedVersion Version;
|
| 623 |
+
|
| 624 |
+
// Mappings from CallStackId to the indexes into the call stack array.
|
| 625 |
+
llvm::DenseMap<CallStackId, LinearCallStackId> *MemProfCallStackIndexes;
|
| 626 |
+
|
| 627 |
+
public:
|
| 628 |
+
// We do not support the default constructor, which does not set Version.
|
| 629 |
+
RecordWriterTrait() = delete;
|
| 630 |
+
RecordWriterTrait(
|
| 631 |
+
const MemProfSchema *Schema, IndexedVersion V,
|
| 632 |
+
llvm::DenseMap<CallStackId, LinearCallStackId> *MemProfCallStackIndexes)
|
| 633 |
+
: Schema(Schema), Version(V),
|
| 634 |
+
MemProfCallStackIndexes(MemProfCallStackIndexes) {}
|
| 635 |
+
|
| 636 |
+
static hash_value_type ComputeHash(key_type_ref K) { return K; }
|
| 637 |
+
|
| 638 |
+
std::pair<offset_type, offset_type>
|
| 639 |
+
EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V) {
|
| 640 |
+
using namespace support;
|
| 641 |
+
|
| 642 |
+
endian::Writer LE(Out, llvm::endianness::little);
|
| 643 |
+
offset_type N = sizeof(K);
|
| 644 |
+
LE.write<offset_type>(N);
|
| 645 |
+
offset_type M = V.serializedSize(*Schema, Version);
|
| 646 |
+
LE.write<offset_type>(M);
|
| 647 |
+
return std::make_pair(N, M);
|
| 648 |
+
}
|
| 649 |
+
|
| 650 |
+
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type /*Unused*/) {
|
| 651 |
+
using namespace support;
|
| 652 |
+
endian::Writer LE(Out, llvm::endianness::little);
|
| 653 |
+
LE.write<uint64_t>(K);
|
| 654 |
+
}
|
| 655 |
+
|
| 656 |
+
void EmitData(raw_ostream &Out, key_type_ref /*Unused*/, data_type_ref V,
|
| 657 |
+
offset_type /*Unused*/) {
|
| 658 |
+
assert(Schema != nullptr && "MemProf schema is not initialized!");
|
| 659 |
+
V.serialize(*Schema, Out, Version, MemProfCallStackIndexes);
|
| 660 |
+
// Clear the IndexedMemProfRecord which results in clearing/freeing its
|
| 661 |
+
// vectors of allocs and callsites. This is owned by the associated on-disk
|
| 662 |
+
// hash table, but unused after this point. See also the comment added to
|
| 663 |
+
// the client which constructs the on-disk hash table for this trait.
|
| 664 |
+
V.clear();
|
| 665 |
+
}
|
| 666 |
+
};
|
| 667 |
+
|
| 668 |
+
// Trait for writing frame mappings to the on-disk hash table.
|
| 669 |
+
class FrameWriterTrait {
|
| 670 |
+
public:
|
| 671 |
+
using key_type = FrameId;
|
| 672 |
+
using key_type_ref = FrameId;
|
| 673 |
+
|
| 674 |
+
using data_type = Frame;
|
| 675 |
+
using data_type_ref = Frame &;
|
| 676 |
+
|
| 677 |
+
using hash_value_type = FrameId;
|
| 678 |
+
using offset_type = uint64_t;
|
| 679 |
+
|
| 680 |
+
static hash_value_type ComputeHash(key_type_ref K) { return K; }
|
| 681 |
+
|
| 682 |
+
static std::pair<offset_type, offset_type>
|
| 683 |
+
EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V) {
|
| 684 |
+
using namespace support;
|
| 685 |
+
endian::Writer LE(Out, llvm::endianness::little);
|
| 686 |
+
offset_type N = sizeof(K);
|
| 687 |
+
LE.write<offset_type>(N);
|
| 688 |
+
offset_type M = V.serializedSize();
|
| 689 |
+
LE.write<offset_type>(M);
|
| 690 |
+
return std::make_pair(N, M);
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type /*Unused*/) {
|
| 694 |
+
using namespace support;
|
| 695 |
+
endian::Writer LE(Out, llvm::endianness::little);
|
| 696 |
+
LE.write<key_type>(K);
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
void EmitData(raw_ostream &Out, key_type_ref /*Unused*/, data_type_ref V,
|
| 700 |
+
offset_type /*Unused*/) {
|
| 701 |
+
V.serialize(Out);
|
| 702 |
+
}
|
| 703 |
+
};
|
| 704 |
+
|
| 705 |
+
// Trait for reading frame mappings from the on-disk hash table.
|
| 706 |
+
class FrameLookupTrait {
|
| 707 |
+
public:
|
| 708 |
+
using data_type = const Frame;
|
| 709 |
+
using internal_key_type = FrameId;
|
| 710 |
+
using external_key_type = FrameId;
|
| 711 |
+
using hash_value_type = FrameId;
|
| 712 |
+
using offset_type = uint64_t;
|
| 713 |
+
|
| 714 |
+
static bool EqualKey(internal_key_type A, internal_key_type B) {
|
| 715 |
+
return A == B;
|
| 716 |
+
}
|
| 717 |
+
static uint64_t GetInternalKey(internal_key_type K) { return K; }
|
| 718 |
+
static uint64_t GetExternalKey(external_key_type K) { return K; }
|
| 719 |
+
|
| 720 |
+
hash_value_type ComputeHash(internal_key_type K) { return K; }
|
| 721 |
+
|
| 722 |
+
static std::pair<offset_type, offset_type>
|
| 723 |
+
ReadKeyDataLength(const unsigned char *&D) {
|
| 724 |
+
using namespace support;
|
| 725 |
+
|
| 726 |
+
offset_type KeyLen =
|
| 727 |
+
endian::readNext<offset_type, llvm::endianness::little>(D);
|
| 728 |
+
offset_type DataLen =
|
| 729 |
+
endian::readNext<offset_type, llvm::endianness::little>(D);
|
| 730 |
+
return std::make_pair(KeyLen, DataLen);
|
| 731 |
+
}
|
| 732 |
+
|
| 733 |
+
uint64_t ReadKey(const unsigned char *D, offset_type /*Unused*/) {
|
| 734 |
+
using namespace support;
|
| 735 |
+
return endian::readNext<external_key_type, llvm::endianness::little>(D);
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
data_type ReadData(uint64_t K, const unsigned char *D,
|
| 739 |
+
offset_type /*Unused*/) {
|
| 740 |
+
return Frame::deserialize(D);
|
| 741 |
+
}
|
| 742 |
+
};
|
| 743 |
+
|
| 744 |
+
// Trait for writing call stacks to the on-disk hash table.
|
| 745 |
+
class CallStackWriterTrait {
|
| 746 |
+
public:
|
| 747 |
+
using key_type = CallStackId;
|
| 748 |
+
using key_type_ref = CallStackId;
|
| 749 |
+
|
| 750 |
+
using data_type = llvm::SmallVector<FrameId>;
|
| 751 |
+
using data_type_ref = llvm::SmallVector<FrameId> &;
|
| 752 |
+
|
| 753 |
+
using hash_value_type = CallStackId;
|
| 754 |
+
using offset_type = uint64_t;
|
| 755 |
+
|
| 756 |
+
static hash_value_type ComputeHash(key_type_ref K) { return K; }
|
| 757 |
+
|
| 758 |
+
static std::pair<offset_type, offset_type>
|
| 759 |
+
EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V) {
|
| 760 |
+
using namespace support;
|
| 761 |
+
endian::Writer LE(Out, llvm::endianness::little);
|
| 762 |
+
// We do not explicitly emit the key length because it is a constant.
|
| 763 |
+
offset_type N = sizeof(K);
|
| 764 |
+
offset_type M = sizeof(FrameId) * V.size();
|
| 765 |
+
LE.write<offset_type>(M);
|
| 766 |
+
return std::make_pair(N, M);
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type /*Unused*/) {
|
| 770 |
+
using namespace support;
|
| 771 |
+
endian::Writer LE(Out, llvm::endianness::little);
|
| 772 |
+
LE.write<key_type>(K);
|
| 773 |
+
}
|
| 774 |
+
|
| 775 |
+
void EmitData(raw_ostream &Out, key_type_ref /*Unused*/, data_type_ref V,
|
| 776 |
+
offset_type /*Unused*/) {
|
| 777 |
+
using namespace support;
|
| 778 |
+
endian::Writer LE(Out, llvm::endianness::little);
|
| 779 |
+
// Emit the frames. We do not explicitly emit the length of the vector
|
| 780 |
+
// because it can be inferred from the data length.
|
| 781 |
+
for (FrameId F : V)
|
| 782 |
+
LE.write<FrameId>(F);
|
| 783 |
+
}
|
| 784 |
+
};
|
| 785 |
+
|
| 786 |
+
// Trait for reading call stack mappings from the on-disk hash table.
|
| 787 |
+
class CallStackLookupTrait {
|
| 788 |
+
public:
|
| 789 |
+
using data_type = const llvm::SmallVector<FrameId>;
|
| 790 |
+
using internal_key_type = CallStackId;
|
| 791 |
+
using external_key_type = CallStackId;
|
| 792 |
+
using hash_value_type = CallStackId;
|
| 793 |
+
using offset_type = uint64_t;
|
| 794 |
+
|
| 795 |
+
static bool EqualKey(internal_key_type A, internal_key_type B) {
|
| 796 |
+
return A == B;
|
| 797 |
+
}
|
| 798 |
+
static uint64_t GetInternalKey(internal_key_type K) { return K; }
|
| 799 |
+
static uint64_t GetExternalKey(external_key_type K) { return K; }
|
| 800 |
+
|
| 801 |
+
hash_value_type ComputeHash(internal_key_type K) { return K; }
|
| 802 |
+
|
| 803 |
+
static std::pair<offset_type, offset_type>
|
| 804 |
+
ReadKeyDataLength(const unsigned char *&D) {
|
| 805 |
+
using namespace support;
|
| 806 |
+
|
| 807 |
+
// We do not explicitly read the key length because it is a constant.
|
| 808 |
+
offset_type KeyLen = sizeof(external_key_type);
|
| 809 |
+
offset_type DataLen =
|
| 810 |
+
endian::readNext<offset_type, llvm::endianness::little>(D);
|
| 811 |
+
return std::make_pair(KeyLen, DataLen);
|
| 812 |
+
}
|
| 813 |
+
|
| 814 |
+
uint64_t ReadKey(const unsigned char *D, offset_type /*Unused*/) {
|
| 815 |
+
using namespace support;
|
| 816 |
+
return endian::readNext<external_key_type, llvm::endianness::little>(D);
|
| 817 |
+
}
|
| 818 |
+
|
| 819 |
+
data_type ReadData(uint64_t K, const unsigned char *D, offset_type Length) {
|
| 820 |
+
using namespace support;
|
| 821 |
+
llvm::SmallVector<FrameId> CS;
|
| 822 |
+
// Derive the number of frames from the data length.
|
| 823 |
+
uint64_t NumFrames = Length / sizeof(FrameId);
|
| 824 |
+
assert(Length % sizeof(FrameId) == 0);
|
| 825 |
+
CS.reserve(NumFrames);
|
| 826 |
+
for (size_t I = 0; I != NumFrames; ++I) {
|
| 827 |
+
FrameId F = endian::readNext<FrameId, llvm::endianness::little>(D);
|
| 828 |
+
CS.push_back(F);
|
| 829 |
+
}
|
| 830 |
+
return CS;
|
| 831 |
+
}
|
| 832 |
+
};
|
| 833 |
+
|
| 834 |
+
struct LineLocation {
|
| 835 |
+
LineLocation(uint32_t L, uint32_t D) : LineOffset(L), Column(D) {}
|
| 836 |
+
|
| 837 |
+
bool operator<(const LineLocation &O) const {
|
| 838 |
+
return std::tie(LineOffset, Column) < std::tie(O.LineOffset, O.Column);
|
| 839 |
+
}
|
| 840 |
+
|
| 841 |
+
bool operator==(const LineLocation &O) const {
|
| 842 |
+
return LineOffset == O.LineOffset && Column == O.Column;
|
| 843 |
+
}
|
| 844 |
+
|
| 845 |
+
bool operator!=(const LineLocation &O) const {
|
| 846 |
+
return LineOffset != O.LineOffset || Column != O.Column;
|
| 847 |
+
}
|
| 848 |
+
|
| 849 |
+
uint64_t getHashCode() const { return ((uint64_t)Column << 32) | LineOffset; }
|
| 850 |
+
|
| 851 |
+
uint32_t LineOffset;
|
| 852 |
+
uint32_t Column;
|
| 853 |
+
};
|
| 854 |
+
|
| 855 |
+
// A pair of a call site location and its corresponding callee GUID.
|
| 856 |
+
using CallEdgeTy = std::pair<LineLocation, uint64_t>;
|
| 857 |
+
} // namespace memprof
|
| 858 |
+
} // namespace llvm
|
| 859 |
+
#endif // LLVM_PROFILEDATA_MEMPROF_H
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/MemProfCommon.h
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- MemProfCommon.h - MemProf common utilities ---------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// This file contains MemProf common utilities.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_PROFILEDATA_MEMPROFCOMMON_H
|
| 14 |
+
#define LLVM_PROFILEDATA_MEMPROFCOMMON_H
|
| 15 |
+
|
| 16 |
+
#include "llvm/IR/ModuleSummaryIndex.h"
|
| 17 |
+
|
| 18 |
+
namespace llvm {
|
| 19 |
+
namespace memprof {
|
| 20 |
+
|
| 21 |
+
struct Frame;
|
| 22 |
+
|
| 23 |
+
/// Return the allocation type for a given set of memory profile values.
|
| 24 |
+
AllocationType getAllocType(uint64_t TotalLifetimeAccessDensity,
|
| 25 |
+
uint64_t AllocCount, uint64_t TotalLifetime);
|
| 26 |
+
|
| 27 |
+
/// Helper to generate a single hash id for a given callstack, used for emitting
|
| 28 |
+
/// matching statistics and useful for uniquing such statistics across modules.
|
| 29 |
+
/// Also used to dedup contexts when computing the summary.
|
| 30 |
+
uint64_t computeFullStackId(ArrayRef<Frame> CallStack);
|
| 31 |
+
|
| 32 |
+
} // namespace memprof
|
| 33 |
+
} // namespace llvm
|
| 34 |
+
|
| 35 |
+
#endif // LLVM_PROFILEDATA_MEMPROFCOMMON_H
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/MemProfData.inc
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef MEMPROF_DATA_INC
|
| 2 |
+
#define MEMPROF_DATA_INC
|
| 3 |
+
/*===-- MemProfData.inc - MemProf profiling runtime structures -*- C++ -*-=== *\
|
| 4 |
+
|*
|
| 5 |
+
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 6 |
+
|* See https://llvm.org/LICENSE.txt for license information.
|
| 7 |
+
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 8 |
+
|*
|
| 9 |
+
\*===----------------------------------------------------------------------===*/
|
| 10 |
+
/*
|
| 11 |
+
* This is the main file that defines all the data structure, signature,
|
| 12 |
+
* constant literals that are shared across profiling runtime library,
|
| 13 |
+
* and host tools (reader/writer).
|
| 14 |
+
*
|
| 15 |
+
* This file has two identical copies. The primary copy lives in LLVM and
|
| 16 |
+
* the other one sits in compiler-rt/include/profile directory. To make changes
|
| 17 |
+
* in this file, first modify the primary copy and copy it over to compiler-rt.
|
| 18 |
+
* Testing of any change in this file can start only after the two copies are
|
| 19 |
+
* synced up.
|
| 20 |
+
*
|
| 21 |
+
\*===----------------------------------------------------------------------===*/
|
| 22 |
+
#include <string.h>
|
| 23 |
+
|
| 24 |
+
#ifdef _MSC_VER
|
| 25 |
+
#define PACKED(...) __pragma(pack(push,1)) __VA_ARGS__ __pragma(pack(pop))
|
| 26 |
+
#else
|
| 27 |
+
#define PACKED(...) __VA_ARGS__ __attribute__((__packed__))
|
| 28 |
+
#endif
|
| 29 |
+
|
| 30 |
+
// A 64-bit magic number to uniquely identify the raw binary memprof profile file.
|
| 31 |
+
#define MEMPROF_RAW_MAGIC_64 \
|
| 32 |
+
((uint64_t)255 << 56 | (uint64_t)'m' << 48 | (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | \
|
| 33 |
+
(uint64_t)'o' << 24 | (uint64_t)'f' << 16 | (uint64_t)'r' << 8 | (uint64_t)129)
|
| 34 |
+
|
| 35 |
+
// The version number of the raw binary format.
|
| 36 |
+
#define MEMPROF_RAW_VERSION 4ULL
|
| 37 |
+
|
| 38 |
+
// Currently supported versions.
|
| 39 |
+
#define MEMPROF_RAW_SUPPORTED_VERSIONS \
|
| 40 |
+
{ 3ULL, 4ULL }
|
| 41 |
+
|
| 42 |
+
#define MEMPROF_V3_MIB_SIZE 132ULL;
|
| 43 |
+
|
| 44 |
+
#define MEMPROF_BUILDID_MAX_SIZE 32ULL
|
| 45 |
+
|
| 46 |
+
namespace llvm {
|
| 47 |
+
namespace memprof {
|
| 48 |
+
// A struct describing the header used for the raw binary memprof profile format.
|
| 49 |
+
PACKED(struct Header {
|
| 50 |
+
uint64_t Magic;
|
| 51 |
+
uint64_t Version;
|
| 52 |
+
uint64_t TotalSize;
|
| 53 |
+
uint64_t SegmentOffset;
|
| 54 |
+
uint64_t MIBOffset;
|
| 55 |
+
uint64_t StackOffset;
|
| 56 |
+
});
|
| 57 |
+
|
| 58 |
+
// A struct describing the information necessary to describe a /proc/maps
|
| 59 |
+
// segment entry for a particular binary/library identified by its build id.
|
| 60 |
+
PACKED(struct SegmentEntry {
|
| 61 |
+
uint64_t Start;
|
| 62 |
+
uint64_t End;
|
| 63 |
+
uint64_t Offset;
|
| 64 |
+
uint64_t BuildIdSize;
|
| 65 |
+
uint8_t BuildId[MEMPROF_BUILDID_MAX_SIZE] = {0};
|
| 66 |
+
|
| 67 |
+
// This constructor is only used in tests so don't set the BuildId.
|
| 68 |
+
SegmentEntry(uint64_t S, uint64_t E, uint64_t O)
|
| 69 |
+
: Start(S), End(E), Offset(O), BuildIdSize(0) {}
|
| 70 |
+
|
| 71 |
+
SegmentEntry(const SegmentEntry& S) {
|
| 72 |
+
Start = S.Start;
|
| 73 |
+
End = S.End;
|
| 74 |
+
Offset = S.Offset;
|
| 75 |
+
BuildIdSize = S.BuildIdSize;
|
| 76 |
+
memcpy(BuildId, S.BuildId, S.BuildIdSize);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
SegmentEntry& operator=(const SegmentEntry& S) {
|
| 80 |
+
Start = S.Start;
|
| 81 |
+
End = S.End;
|
| 82 |
+
Offset = S.Offset;
|
| 83 |
+
BuildIdSize = S.BuildIdSize;
|
| 84 |
+
memcpy(BuildId, S.BuildId, S.BuildIdSize);
|
| 85 |
+
return *this;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
bool operator==(const SegmentEntry& S) const {
|
| 89 |
+
return Start == S.Start && End == S.End && Offset == S.Offset &&
|
| 90 |
+
BuildIdSize == S.BuildIdSize &&
|
| 91 |
+
memcmp(BuildId, S.BuildId, S.BuildIdSize) == 0;
|
| 92 |
+
}
|
| 93 |
+
});
|
| 94 |
+
|
| 95 |
+
// Packed struct definition for MSVC. We can't use the PACKED macro defined in
|
| 96 |
+
// MemProfData.inc since it would mean we are embedding a directive (the
|
| 97 |
+
// #include for MIBEntryDef) into the macros which is undefined behaviour.
|
| 98 |
+
#ifdef _MSC_VER
|
| 99 |
+
__pragma(pack(push,1))
|
| 100 |
+
#endif
|
| 101 |
+
|
| 102 |
+
// A struct representing the heap allocation characteristics of a particular
|
| 103 |
+
// runtime context. This struct is shared between the compiler-rt runtime and
|
| 104 |
+
// the raw profile reader. The indexed format uses a separate, self-describing
|
| 105 |
+
// backwards compatible format.
|
| 106 |
+
struct MemInfoBlock{
|
| 107 |
+
|
| 108 |
+
#define MIBEntryDef(NameTag, Name, Type) Type Name;
|
| 109 |
+
#include "MIBEntryDef.inc"
|
| 110 |
+
#undef MIBEntryDef
|
| 111 |
+
|
| 112 |
+
bool operator==(const MemInfoBlock& Other) const {
|
| 113 |
+
bool IsEqual = true;
|
| 114 |
+
#define MIBEntryDef(NameTag, Name, Type) \
|
| 115 |
+
IsEqual = (IsEqual && Name == Other.Name);
|
| 116 |
+
#include "MIBEntryDef.inc"
|
| 117 |
+
#undef MIBEntryDef
|
| 118 |
+
return IsEqual;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
MemInfoBlock() {
|
| 122 |
+
#define MIBEntryDef(NameTag, Name, Type) Name = Type();
|
| 123 |
+
#include "MIBEntryDef.inc"
|
| 124 |
+
#undef MIBEntryDef
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
MemInfoBlock(uint32_t Size, uint64_t AccessCount, uint32_t AllocTs,
|
| 128 |
+
uint32_t DeallocTs, uint32_t AllocCpu, uint32_t DeallocCpu,
|
| 129 |
+
uintptr_t Histogram, uint32_t HistogramSize)
|
| 130 |
+
: MemInfoBlock() {
|
| 131 |
+
AllocCount = 1U;
|
| 132 |
+
TotalAccessCount = AccessCount;
|
| 133 |
+
MinAccessCount = AccessCount;
|
| 134 |
+
MaxAccessCount = AccessCount;
|
| 135 |
+
TotalSize = Size;
|
| 136 |
+
MinSize = Size;
|
| 137 |
+
MaxSize = Size;
|
| 138 |
+
AllocTimestamp = AllocTs;
|
| 139 |
+
DeallocTimestamp = DeallocTs;
|
| 140 |
+
TotalLifetime = DeallocTimestamp - AllocTimestamp;
|
| 141 |
+
MinLifetime = TotalLifetime;
|
| 142 |
+
MaxLifetime = TotalLifetime;
|
| 143 |
+
// Access density is accesses per byte. Multiply by 100 to include the
|
| 144 |
+
// fractional part.
|
| 145 |
+
TotalAccessDensity = AccessCount * 100 / Size;
|
| 146 |
+
MinAccessDensity = TotalAccessDensity;
|
| 147 |
+
MaxAccessDensity = TotalAccessDensity;
|
| 148 |
+
// Lifetime access density is the access density per second of lifetime.
|
| 149 |
+
// Multiply by 1000 to convert denominator lifetime to seconds (using a
|
| 150 |
+
// minimum lifetime of 1ms to avoid divide by 0. Do the multiplication first
|
| 151 |
+
// to reduce truncations to 0.
|
| 152 |
+
TotalLifetimeAccessDensity =
|
| 153 |
+
TotalAccessDensity * 1000 / (TotalLifetime ? TotalLifetime : 1);
|
| 154 |
+
MinLifetimeAccessDensity = TotalLifetimeAccessDensity;
|
| 155 |
+
MaxLifetimeAccessDensity = TotalLifetimeAccessDensity;
|
| 156 |
+
AllocCpuId = AllocCpu;
|
| 157 |
+
DeallocCpuId = DeallocCpu;
|
| 158 |
+
NumMigratedCpu = AllocCpuId != DeallocCpuId;
|
| 159 |
+
AccessHistogramSize = HistogramSize;
|
| 160 |
+
AccessHistogram = Histogram;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
void Merge(const MemInfoBlock &newMIB) {
|
| 164 |
+
AllocCount += newMIB.AllocCount;
|
| 165 |
+
|
| 166 |
+
TotalAccessCount += newMIB.TotalAccessCount;
|
| 167 |
+
MinAccessCount = newMIB.MinAccessCount < MinAccessCount ? newMIB.MinAccessCount : MinAccessCount;
|
| 168 |
+
MaxAccessCount = newMIB.MaxAccessCount > MaxAccessCount ? newMIB.MaxAccessCount : MaxAccessCount;
|
| 169 |
+
|
| 170 |
+
TotalSize += newMIB.TotalSize;
|
| 171 |
+
MinSize = newMIB.MinSize < MinSize ? newMIB.MinSize : MinSize;
|
| 172 |
+
MaxSize = newMIB.MaxSize > MaxSize ? newMIB.MaxSize : MaxSize;
|
| 173 |
+
|
| 174 |
+
TotalLifetime += newMIB.TotalLifetime;
|
| 175 |
+
MinLifetime = newMIB.MinLifetime < MinLifetime ? newMIB.MinLifetime : MinLifetime;
|
| 176 |
+
MaxLifetime = newMIB.MaxLifetime > MaxLifetime ? newMIB.MaxLifetime : MaxLifetime;
|
| 177 |
+
|
| 178 |
+
TotalAccessDensity += newMIB.TotalAccessDensity;
|
| 179 |
+
MinAccessDensity = newMIB.MinAccessDensity < MinAccessDensity
|
| 180 |
+
? newMIB.MinAccessDensity
|
| 181 |
+
: MinAccessDensity;
|
| 182 |
+
MaxAccessDensity = newMIB.MaxAccessDensity > MaxAccessDensity
|
| 183 |
+
? newMIB.MaxAccessDensity
|
| 184 |
+
: MaxAccessDensity;
|
| 185 |
+
|
| 186 |
+
TotalLifetimeAccessDensity += newMIB.TotalLifetimeAccessDensity;
|
| 187 |
+
MinLifetimeAccessDensity =
|
| 188 |
+
newMIB.MinLifetimeAccessDensity < MinLifetimeAccessDensity
|
| 189 |
+
? newMIB.MinLifetimeAccessDensity
|
| 190 |
+
: MinLifetimeAccessDensity;
|
| 191 |
+
MaxLifetimeAccessDensity =
|
| 192 |
+
newMIB.MaxLifetimeAccessDensity > MaxLifetimeAccessDensity
|
| 193 |
+
? newMIB.MaxLifetimeAccessDensity
|
| 194 |
+
: MaxLifetimeAccessDensity;
|
| 195 |
+
|
| 196 |
+
// We know newMIB was deallocated later, so just need to check if it was
|
| 197 |
+
// allocated before last one deallocated.
|
| 198 |
+
NumLifetimeOverlaps += newMIB.AllocTimestamp < DeallocTimestamp;
|
| 199 |
+
AllocTimestamp = newMIB.AllocTimestamp;
|
| 200 |
+
DeallocTimestamp = newMIB.DeallocTimestamp;
|
| 201 |
+
|
| 202 |
+
NumSameAllocCpu += AllocCpuId == newMIB.AllocCpuId;
|
| 203 |
+
NumSameDeallocCpu += DeallocCpuId == newMIB.DeallocCpuId;
|
| 204 |
+
AllocCpuId = newMIB.AllocCpuId;
|
| 205 |
+
DeallocCpuId = newMIB.DeallocCpuId;
|
| 206 |
+
|
| 207 |
+
// For merging histograms, we always keep the longer histogram, and add
|
| 208 |
+
// values of shorter histogram to larger one.
|
| 209 |
+
uintptr_t ShorterHistogram;
|
| 210 |
+
uint32_t ShorterHistogramSize;
|
| 211 |
+
if (newMIB.AccessHistogramSize > AccessHistogramSize) {
|
| 212 |
+
ShorterHistogram = AccessHistogram;
|
| 213 |
+
ShorterHistogramSize = AccessHistogramSize;
|
| 214 |
+
// Swap histogram of current to larger histogram
|
| 215 |
+
AccessHistogram = newMIB.AccessHistogram;
|
| 216 |
+
AccessHistogramSize = newMIB.AccessHistogramSize;
|
| 217 |
+
} else {
|
| 218 |
+
ShorterHistogram = newMIB.AccessHistogram;
|
| 219 |
+
ShorterHistogramSize = newMIB.AccessHistogramSize;
|
| 220 |
+
}
|
| 221 |
+
for (size_t i = 0; i < ShorterHistogramSize; ++i) {
|
| 222 |
+
((uint64_t *)AccessHistogram)[i] += ((uint64_t *)ShorterHistogram)[i];
|
| 223 |
+
}
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
#ifdef _MSC_VER
|
| 227 |
+
} __pragma(pack(pop));
|
| 228 |
+
#else
|
| 229 |
+
} __attribute__((__packed__));
|
| 230 |
+
#endif
|
| 231 |
+
|
| 232 |
+
} // namespace memprof
|
| 233 |
+
} // namespace llvm
|
| 234 |
+
|
| 235 |
+
#endif
|
deps/exla/cache/xla_extension/include/llvm/ProfileData/MemProfRadixTree.h
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===- MemProfRadixTree.h - MemProf format support ------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// A custom Radix Tree builder for memprof data to optimize for space.
|
| 10 |
+
//
|
| 11 |
+
//===----------------------------------------------------------------------===//
|
| 12 |
+
|
| 13 |
+
#ifndef LLVM_PROFILEDATA_MEMPROFRADIXTREE_H
|
| 14 |
+
#define LLVM_PROFILEDATA_MEMPROFRADIXTREE_H
|
| 15 |
+
|
| 16 |
+
#include "llvm/ProfileData/IndexedMemProfData.h"
|
| 17 |
+
#include "llvm/ProfileData/MemProf.h"
|
| 18 |
+
|
| 19 |
+
namespace llvm {
|
| 20 |
+
namespace memprof {
|
| 21 |
+
namespace detail {
|
| 22 |
+
// "Dereference" the iterator from DenseMap or OnDiskChainedHashTable. We have
|
| 23 |
+
// to do so in one of two different ways depending on the type of the hash
|
| 24 |
+
// table.
|
| 25 |
+
template <typename value_type, typename IterTy>
|
| 26 |
+
value_type DerefIterator(IterTy Iter) {
|
| 27 |
+
using deref_type = llvm::remove_cvref_t<decltype(*Iter)>;
|
| 28 |
+
if constexpr (std::is_same_v<deref_type, value_type>)
|
| 29 |
+
return *Iter;
|
| 30 |
+
else
|
| 31 |
+
return Iter->second;
|
| 32 |
+
}
|
| 33 |
+
} // namespace detail
|
| 34 |
+
|
| 35 |
+
// A function object that returns a frame for a given FrameId.
|
| 36 |
+
template <typename MapTy> struct FrameIdConverter {
|
| 37 |
+
std::optional<FrameId> LastUnmappedId;
|
| 38 |
+
MapTy ⤅
|
| 39 |
+
|
| 40 |
+
FrameIdConverter() = delete;
|
| 41 |
+
FrameIdConverter(MapTy &Map) : Map(Map) {}
|
| 42 |
+
|
| 43 |
+
// Delete the copy constructor and copy assignment operator to avoid a
|
| 44 |
+
// situation where a copy of FrameIdConverter gets an error in LastUnmappedId
|
| 45 |
+
// while the original instance doesn't.
|
| 46 |
+
FrameIdConverter(const FrameIdConverter &) = delete;
|
| 47 |
+
FrameIdConverter &operator=(const FrameIdConverter &) = delete;
|
| 48 |
+
|
| 49 |
+
Frame operator()(FrameId Id) {
|
| 50 |
+
auto Iter = Map.find(Id);
|
| 51 |
+
if (Iter == Map.end()) {
|
| 52 |
+
LastUnmappedId = Id;
|
| 53 |
+
return Frame();
|
| 54 |
+
}
|
| 55 |
+
return detail::DerefIterator<Frame>(Iter);
|
| 56 |
+
}
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
// A function object that returns a call stack for a given CallStackId.
|
| 60 |
+
template <typename MapTy> struct CallStackIdConverter {
|
| 61 |
+
std::optional<CallStackId> LastUnmappedId;
|
| 62 |
+
MapTy ⤅
|
| 63 |
+
llvm::function_ref<Frame(FrameId)> FrameIdToFrame;
|
| 64 |
+
|
| 65 |
+
CallStackIdConverter() = delete;
|
| 66 |
+
CallStackIdConverter(MapTy &Map,
|
| 67 |
+
llvm::function_ref<Frame(FrameId)> FrameIdToFrame)
|
| 68 |
+
: Map(Map), FrameIdToFrame(FrameIdToFrame) {}
|
| 69 |
+
|
| 70 |
+
// Delete the copy constructor and copy assignment operator to avoid a
|
| 71 |
+
// situation where a copy of CallStackIdConverter gets an error in
|
| 72 |
+
// LastUnmappedId while the original instance doesn't.
|
| 73 |
+
CallStackIdConverter(const CallStackIdConverter &) = delete;
|
| 74 |
+
CallStackIdConverter &operator=(const CallStackIdConverter &) = delete;
|
| 75 |
+
|
| 76 |
+
std::vector<Frame> operator()(CallStackId CSId) {
|
| 77 |
+
std::vector<Frame> Frames;
|
| 78 |
+
auto CSIter = Map.find(CSId);
|
| 79 |
+
if (CSIter == Map.end()) {
|
| 80 |
+
LastUnmappedId = CSId;
|
| 81 |
+
} else {
|
| 82 |
+
llvm::SmallVector<FrameId> CS =
|
| 83 |
+
detail::DerefIterator<llvm::SmallVector<FrameId>>(CSIter);
|
| 84 |
+
Frames.reserve(CS.size());
|
| 85 |
+
for (FrameId Id : CS)
|
| 86 |
+
Frames.push_back(FrameIdToFrame(Id));
|
| 87 |
+
}
|
| 88 |
+
return Frames;
|
| 89 |
+
}
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
// A function object that returns a Frame stored at a given index into the Frame
|
| 93 |
+
// array in the profile.
|
| 94 |
+
struct LinearFrameIdConverter {
|
| 95 |
+
const unsigned char *FrameBase;
|
| 96 |
+
|
| 97 |
+
LinearFrameIdConverter() = delete;
|
| 98 |
+
LinearFrameIdConverter(const unsigned char *FrameBase)
|
| 99 |
+
: FrameBase(FrameBase) {}
|
| 100 |
+
|
| 101 |
+
Frame operator()(LinearFrameId LinearId) {
|
| 102 |
+
uint64_t Offset = static_cast<uint64_t>(LinearId) * Frame::serializedSize();
|
| 103 |
+
return Frame::deserialize(FrameBase + Offset);
|
| 104 |
+
}
|
| 105 |
+
};
|
| 106 |
+
|
| 107 |
+
// A function object that returns a call stack stored at a given index into the
|
| 108 |
+
// call stack array in the profile.
|
| 109 |
+
struct LinearCallStackIdConverter {
|
| 110 |
+
const unsigned char *CallStackBase;
|
| 111 |
+
llvm::function_ref<Frame(LinearFrameId)> FrameIdToFrame;
|
| 112 |
+
|
| 113 |
+
LinearCallStackIdConverter() = delete;
|
| 114 |
+
LinearCallStackIdConverter(
|
| 115 |
+
const unsigned char *CallStackBase,
|
| 116 |
+
llvm::function_ref<Frame(LinearFrameId)> FrameIdToFrame)
|
| 117 |
+
: CallStackBase(CallStackBase), FrameIdToFrame(FrameIdToFrame) {}
|
| 118 |
+
|
| 119 |
+
std::vector<Frame> operator()(LinearCallStackId LinearCSId) {
|
| 120 |
+
std::vector<Frame> Frames;
|
| 121 |
+
|
| 122 |
+
const unsigned char *Ptr =
|
| 123 |
+
CallStackBase +
|
| 124 |
+
static_cast<uint64_t>(LinearCSId) * sizeof(LinearFrameId);
|
| 125 |
+
uint32_t NumFrames =
|
| 126 |
+
support::endian::readNext<uint32_t, llvm::endianness::little>(Ptr);
|
| 127 |
+
Frames.reserve(NumFrames);
|
| 128 |
+
for (; NumFrames; --NumFrames) {
|
| 129 |
+
LinearFrameId Elem =
|
| 130 |
+
support::endian::read<LinearFrameId, llvm::endianness::little>(Ptr);
|
| 131 |
+
// Follow a pointer to the parent, if any. See comments below on
|
| 132 |
+
// CallStackRadixTreeBuilder for the description of the radix tree format.
|
| 133 |
+
if (static_cast<std::make_signed_t<LinearFrameId>>(Elem) < 0) {
|
| 134 |
+
Ptr += (-Elem) * sizeof(LinearFrameId);
|
| 135 |
+
Elem =
|
| 136 |
+
support::endian::read<LinearFrameId, llvm::endianness::little>(Ptr);
|
| 137 |
+
}
|
| 138 |
+
// We shouldn't encounter another pointer.
|
| 139 |
+
assert(static_cast<std::make_signed_t<LinearFrameId>>(Elem) >= 0);
|
| 140 |
+
Frames.push_back(FrameIdToFrame(Elem));
|
| 141 |
+
Ptr += sizeof(LinearFrameId);
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
return Frames;
|
| 145 |
+
}
|
| 146 |
+
};
|
| 147 |
+
|
| 148 |
+
// Used to extract caller-callee pairs from the call stack array. The leaf
|
| 149 |
+
// frame is assumed to call a heap allocation function with GUID 0. The
|
| 150 |
+
// resulting pairs are accumulated in CallerCalleePairs. Users can take it
|
| 151 |
+
// with:
|
| 152 |
+
//
|
| 153 |
+
// auto Pairs = std::move(Extractor.CallerCalleePairs);
|
| 154 |
+
struct CallerCalleePairExtractor {
|
| 155 |
+
// The base address of the radix tree array.
|
| 156 |
+
const unsigned char *CallStackBase;
|
| 157 |
+
// A functor to convert a linear FrameId to a Frame.
|
| 158 |
+
llvm::function_ref<Frame(LinearFrameId)> FrameIdToFrame;
|
| 159 |
+
// A map from caller GUIDs to lists of call sites in respective callers.
|
| 160 |
+
DenseMap<uint64_t, SmallVector<CallEdgeTy, 0>> CallerCalleePairs;
|
| 161 |
+
|
| 162 |
+
// The set of linear call stack IDs that we've visited.
|
| 163 |
+
BitVector Visited;
|
| 164 |
+
|
| 165 |
+
CallerCalleePairExtractor() = delete;
|
| 166 |
+
CallerCalleePairExtractor(
|
| 167 |
+
const unsigned char *CallStackBase,
|
| 168 |
+
llvm::function_ref<Frame(LinearFrameId)> FrameIdToFrame,
|
| 169 |
+
unsigned RadixTreeSize)
|
| 170 |
+
: CallStackBase(CallStackBase), FrameIdToFrame(FrameIdToFrame),
|
| 171 |
+
Visited(RadixTreeSize) {}
|
| 172 |
+
|
| 173 |
+
void operator()(LinearCallStackId LinearCSId) {
|
| 174 |
+
const unsigned char *Ptr =
|
| 175 |
+
CallStackBase +
|
| 176 |
+
static_cast<uint64_t>(LinearCSId) * sizeof(LinearFrameId);
|
| 177 |
+
uint32_t NumFrames =
|
| 178 |
+
support::endian::readNext<uint32_t, llvm::endianness::little>(Ptr);
|
| 179 |
+
// The leaf frame calls a function with GUID 0.
|
| 180 |
+
uint64_t CalleeGUID = 0;
|
| 181 |
+
for (; NumFrames; --NumFrames) {
|
| 182 |
+
LinearFrameId Elem =
|
| 183 |
+
support::endian::read<LinearFrameId, llvm::endianness::little>(Ptr);
|
| 184 |
+
// Follow a pointer to the parent, if any. See comments below on
|
| 185 |
+
// CallStackRadixTreeBuilder for the description of the radix tree format.
|
| 186 |
+
if (static_cast<std::make_signed_t<LinearFrameId>>(Elem) < 0) {
|
| 187 |
+
Ptr += (-Elem) * sizeof(LinearFrameId);
|
| 188 |
+
Elem =
|
| 189 |
+
support::endian::read<LinearFrameId, llvm::endianness::little>(Ptr);
|
| 190 |
+
}
|
| 191 |
+
// We shouldn't encounter another pointer.
|
| 192 |
+
assert(static_cast<std::make_signed_t<LinearFrameId>>(Elem) >= 0);
|
| 193 |
+
|
| 194 |
+
// Add a new caller-callee pair.
|
| 195 |
+
Frame F = FrameIdToFrame(Elem);
|
| 196 |
+
uint64_t CallerGUID = F.Function;
|
| 197 |
+
LineLocation Loc(F.LineOffset, F.Column);
|
| 198 |
+
CallerCalleePairs[CallerGUID].emplace_back(Loc, CalleeGUID);
|
| 199 |
+
|
| 200 |
+
// Keep track of the indices we've visited. If we've already visited the
|
| 201 |
+
// current one, terminate the traversal. We will not discover any new
|
| 202 |
+
// caller-callee pair by continuing the traversal.
|
| 203 |
+
unsigned Offset =
|
| 204 |
+
std::distance(CallStackBase, Ptr) / sizeof(LinearFrameId);
|
| 205 |
+
if (Visited.test(Offset))
|
| 206 |
+
break;
|
| 207 |
+
Visited.set(Offset);
|
| 208 |
+
|
| 209 |
+
Ptr += sizeof(LinearFrameId);
|
| 210 |
+
CalleeGUID = CallerGUID;
|
| 211 |
+
}
|
| 212 |
+
}
|
| 213 |
+
};
|
| 214 |
+
|
| 215 |
+
// A convenience wrapper around FrameIdConverter and CallStackIdConverter for
|
| 216 |
+
// tests.
|
| 217 |
+
struct IndexedCallstackIdConverter {
|
| 218 |
+
IndexedCallstackIdConverter() = delete;
|
| 219 |
+
IndexedCallstackIdConverter(IndexedMemProfData &MemProfData)
|
| 220 |
+
: FrameIdConv(MemProfData.Frames),
|
| 221 |
+
CSIdConv(MemProfData.CallStacks, FrameIdConv) {}
|
| 222 |
+
|
| 223 |
+
// Delete the copy constructor and copy assignment operator to avoid a
|
| 224 |
+
// situation where a copy of IndexedCallstackIdConverter gets an error in
|
| 225 |
+
// LastUnmappedId while the original instance doesn't.
|
| 226 |
+
IndexedCallstackIdConverter(const IndexedCallstackIdConverter &) = delete;
|
| 227 |
+
IndexedCallstackIdConverter &
|
| 228 |
+
operator=(const IndexedCallstackIdConverter &) = delete;
|
| 229 |
+
|
| 230 |
+
std::vector<Frame> operator()(CallStackId CSId) { return CSIdConv(CSId); }
|
| 231 |
+
|
| 232 |
+
FrameIdConverter<decltype(IndexedMemProfData::Frames)> FrameIdConv;
|
| 233 |
+
CallStackIdConverter<decltype(IndexedMemProfData::CallStacks)> CSIdConv;
|
| 234 |
+
};
|
| 235 |
+
|
| 236 |
+
struct FrameStat {
|
| 237 |
+
// The number of occurrences of a given FrameId.
|
| 238 |
+
uint64_t Count = 0;
|
| 239 |
+
// The sum of indexes where a given FrameId shows up.
|
| 240 |
+
uint64_t PositionSum = 0;
|
| 241 |
+
};
|
| 242 |
+
|
| 243 |
+
// Compute a histogram of Frames in call stacks.
|
| 244 |
+
template <typename FrameIdTy>
|
| 245 |
+
llvm::DenseMap<FrameIdTy, FrameStat>
|
| 246 |
+
computeFrameHistogram(llvm::MapVector<CallStackId, llvm::SmallVector<FrameIdTy>>
|
| 247 |
+
&MemProfCallStackData);
|
| 248 |
+
|
| 249 |
+
// Construct a radix tree of call stacks.
|
| 250 |
+
//
|
| 251 |
+
// A set of call stacks might look like:
|
| 252 |
+
//
|
| 253 |
+
// CallStackId 1: f1 -> f2 -> f3
|
| 254 |
+
// CallStackId 2: f1 -> f2 -> f4 -> f5
|
| 255 |
+
// CallStackId 3: f1 -> f2 -> f4 -> f6
|
| 256 |
+
// CallStackId 4: f7 -> f8 -> f9
|
| 257 |
+
//
|
| 258 |
+
// where each fn refers to a stack frame.
|
| 259 |
+
//
|
| 260 |
+
// Since we expect a lot of common prefixes, we can compress the call stacks
|
| 261 |
+
// into a radix tree like:
|
| 262 |
+
//
|
| 263 |
+
// CallStackId 1: f1 -> f2 -> f3
|
| 264 |
+
// |
|
| 265 |
+
// CallStackId 2: +---> f4 -> f5
|
| 266 |
+
// |
|
| 267 |
+
// CallStackId 3: +---> f6
|
| 268 |
+
//
|
| 269 |
+
// CallStackId 4: f7 -> f8 -> f9
|
| 270 |
+
//
|
| 271 |
+
// Now, we are interested in retrieving call stacks for a given CallStackId, so
|
| 272 |
+
// we just need a pointer from a given call stack to its parent. For example,
|
| 273 |
+
// CallStackId 2 would point to CallStackId 1 as a parent.
|
| 274 |
+
//
|
| 275 |
+
// We serialize the radix tree above into a single array along with the length
|
| 276 |
+
// of each call stack and pointers to the parent call stacks.
|
| 277 |
+
//
|
| 278 |
+
// Index: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
| 279 |
+
// Array: L3 f9 f8 f7 L4 f6 J3 L4 f5 f4 J3 L3 f3 f2 f1
|
| 280 |
+
// ^ ^ ^ ^
|
| 281 |
+
// | | | |
|
| 282 |
+
// CallStackId 4: 0 --+ | | |
|
| 283 |
+
// CallStackId 3: 4 --------------+ | |
|
| 284 |
+
// CallStackId 2: 7 -----------------------+ |
|
| 285 |
+
// CallStackId 1: 11 -----------------------------------+
|
| 286 |
+
//
|
| 287 |
+
// - LN indicates the length of a call stack, encoded as ordinary integer N.
|
| 288 |
+
//
|
| 289 |
+
// - JN indicates a pointer to the parent, encoded as -N.
|
| 290 |
+
//
|
| 291 |
+
// The radix tree allows us to reconstruct call stacks in the leaf-to-root
|
| 292 |
+
// order as we scan the array from left ro right while following pointers to
|
| 293 |
+
// parents along the way.
|
| 294 |
+
//
|
| 295 |
+
// For example, if we are decoding CallStackId 2, we start a forward traversal
|
| 296 |
+
// at Index 7, noting the call stack length of 4 and obtaining f5 and f4. When
|
| 297 |
+
// we see J3 at Index 10, we resume a forward traversal at Index 13 = 10 + 3,
|
| 298 |
+
// picking up f2 and f1. We are done after collecting 4 frames as indicated at
|
| 299 |
+
// the beginning of the traversal.
|
| 300 |
+
//
|
| 301 |
+
// On-disk IndexedMemProfRecord will refer to call stacks by their indexes into
|
| 302 |
+
// the radix tree array, so we do not explicitly encode mappings like:
|
| 303 |
+
// "CallStackId 1 -> 11".
|
| 304 |
+
template <typename FrameIdTy> class CallStackRadixTreeBuilder {
|
| 305 |
+
// The radix tree array.
|
| 306 |
+
std::vector<LinearFrameId> RadixArray;
|
| 307 |
+
|
| 308 |
+
// Mapping from CallStackIds to indexes into RadixArray.
|
| 309 |
+
llvm::DenseMap<CallStackId, LinearCallStackId> CallStackPos;
|
| 310 |
+
|
| 311 |
+
// In build, we partition a given call stack into two parts -- the prefix
|
| 312 |
+
// that's common with the previously encoded call stack and the frames beyond
|
| 313 |
+
// the common prefix -- the unique portion. Then we want to find out where
|
| 314 |
+
// the common prefix is stored in RadixArray so that we can link the unique
|
| 315 |
+
// portion to the common prefix. Indexes, declared below, helps with our
|
| 316 |
+
// needs. Intuitively, Indexes tells us where each of the previously encoded
|
| 317 |
+
// call stack is stored in RadixArray. More formally, Indexes satisfies:
|
| 318 |
+
//
|
| 319 |
+
// RadixArray[Indexes[I]] == Prev[I]
|
| 320 |
+
//
|
| 321 |
+
// for every I, where Prev is the the call stack in the root-to-leaf order
|
| 322 |
+
// previously encoded by build. (Note that Prev, as passed to
|
| 323 |
+
// encodeCallStack, is in the leaf-to-root order.)
|
| 324 |
+
//
|
| 325 |
+
// For example, if the call stack being encoded shares 5 frames at the root of
|
| 326 |
+
// the call stack with the previously encoded call stack,
|
| 327 |
+
// RadixArray[Indexes[0]] is the root frame of the common prefix.
|
| 328 |
+
// RadixArray[Indexes[5 - 1]] is the last frame of the common prefix.
|
| 329 |
+
std::vector<LinearCallStackId> Indexes;
|
| 330 |
+
|
| 331 |
+
using CSIdPair = std::pair<CallStackId, llvm::SmallVector<FrameIdTy>>;
|
| 332 |
+
|
| 333 |
+
// Encode a call stack into RadixArray. Return the starting index within
|
| 334 |
+
// RadixArray.
|
| 335 |
+
LinearCallStackId encodeCallStack(
|
| 336 |
+
const llvm::SmallVector<FrameIdTy> *CallStack,
|
| 337 |
+
const llvm::SmallVector<FrameIdTy> *Prev,
|
| 338 |
+
const llvm::DenseMap<FrameIdTy, LinearFrameId> *MemProfFrameIndexes);
|
| 339 |
+
|
| 340 |
+
public:
|
| 341 |
+
CallStackRadixTreeBuilder() = default;
|
| 342 |
+
|
| 343 |
+
// Build a radix tree array.
|
| 344 |
+
void
|
| 345 |
+
build(llvm::MapVector<CallStackId, llvm::SmallVector<FrameIdTy>>
|
| 346 |
+
&&MemProfCallStackData,
|
| 347 |
+
const llvm::DenseMap<FrameIdTy, LinearFrameId> *MemProfFrameIndexes,
|
| 348 |
+
llvm::DenseMap<FrameIdTy, FrameStat> &FrameHistogram);
|
| 349 |
+
|
| 350 |
+
ArrayRef<LinearFrameId> getRadixArray() const { return RadixArray; }
|
| 351 |
+
|
| 352 |
+
llvm::DenseMap<CallStackId, LinearCallStackId> takeCallStackPos() {
|
| 353 |
+
return std::move(CallStackPos);
|
| 354 |
+
}
|
| 355 |
+
};
|
| 356 |
+
} // namespace memprof
|
| 357 |
+
} // namespace llvm
|
| 358 |
+
#endif // LLVM_PROFILEDATA_MEMPROFRADIXTREE_H
|