78 void XRayInstrumentation::replaceRetWithPatchableRet(
83 for (
auto &MBB : MF) {
84 for (
auto &
T : MBB.terminators()) {
89 Opc = TargetOpcode::PATCHABLE_RET;
94 Opc = TargetOpcode::PATCHABLE_TAIL_CALL;
97 auto MIB =
BuildMI(MBB,
T,
T.getDebugLoc(), TII->
get(Opc))
98 .addImm(
T.getOpcode());
99 for (
auto &MO :
T.operands())
106 for (
auto &
I : Terminators)
107 I->eraseFromParent();
110 void XRayInstrumentation::prependRetWithPatchableExit(
112 for (
auto &MBB : MF) {
113 for (
auto &
T : MBB.terminators()) {
116 Opc = TargetOpcode::PATCHABLE_FUNCTION_EXIT;
119 Opc = TargetOpcode::PATCHABLE_TAIL_CALL;
132 auto InstrAttr =
F.getFnAttribute(
"function-instrument");
134 InstrAttr.isStringAttribute() &&
135 InstrAttr.getValueAsString() ==
"xray-always";
136 Attribute Attr =
F.getFnAttribute(
"xray-instruction-threshold");
137 unsigned XRayThreshold = 0;
138 if (!AlwaysInstrument) {
146 for (
const auto& MBB : MF)
147 MICount += MBB.size();
153 if (MLI.
empty() && MICount < XRayThreshold)
164 auto *TII = MF.getSubtarget().getInstrInfo();
165 auto &FirstMBB = *MBI;
166 auto &FirstMI = *FirstMBB.begin();
168 if (!MF.getSubtarget().isXRaySupported()) {
169 FirstMI.emitError(
"An attempt to perform XRay instrumentation for an"
170 " unsupported target.");
176 BuildMI(FirstMBB, FirstMI, FirstMI.getDebugLoc(),
177 TII->
get(TargetOpcode::PATCHABLE_FUNCTION_ENTER));
179 switch (MF.getTarget().getTargetTriple().getArch()) {
180 case Triple::ArchType::arm:
181 case Triple::ArchType::thumb:
182 case Triple::ArchType::aarch64:
183 case Triple::ArchType::ppc64le:
184 case Triple::ArchType::mips:
185 case Triple::ArchType::mipsel:
186 case Triple::ArchType::mips64:
187 case Triple::ArchType::mips64el:
189 prependRetWithPatchableExit(MF, TII);
194 replaceRetWithPatchableRet(MF, TII);
203 "Insert XRay ops",
false,
false)
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
void push_back(const T &Elt)
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
const MachineInstrBuilder & add(const MachineOperand &MO) const
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
This file contains the simple types necessary to represent the attributes associated with functions a...
No attributes have been set.
char & XRayInstrumentationID
This pass inserts the XRay instrumentation sleds if they are supported by the target platform...
TargetInstrInfo - Interface to description of machine instruction set.
void initializeXRayInstrumentationPass(PassRegistry &)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool isTailCall(const MachineInstr &Inst) const
Determines whether Inst is a tail call instruction.
Represent the analysis usage information of a pass.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
unsigned getReturnOpcode() const
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
void setPreservesCFG()
This function should be called by the pass, iff they do not:
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
StringRef getValueAsString() const
Return the attribute's value as a string.
auto find_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
INITIALIZE_PASS_BEGIN(XRayInstrumentation,"xray-instrumentation","Insert XRay ops", false, false) INITIALIZE_PASS_END(XRayInstrumentation