109467b48Spatrick //===- MachineFunction.cpp ------------------------------------------------===//
209467b48Spatrick //
309467b48Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
409467b48Spatrick // See https://llvm.org/LICENSE.txt for license information.
509467b48Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
609467b48Spatrick //
709467b48Spatrick //===----------------------------------------------------------------------===//
809467b48Spatrick //
909467b48Spatrick // Collect native machine code information for a function. This allows
1009467b48Spatrick // target-specific information about the generated code to be stored with each
1109467b48Spatrick // function.
1209467b48Spatrick //
1309467b48Spatrick //===----------------------------------------------------------------------===//
1409467b48Spatrick
1509467b48Spatrick #include "llvm/CodeGen/MachineFunction.h"
1609467b48Spatrick #include "llvm/ADT/BitVector.h"
1709467b48Spatrick #include "llvm/ADT/DenseMap.h"
1809467b48Spatrick #include "llvm/ADT/DenseSet.h"
1909467b48Spatrick #include "llvm/ADT/STLExtras.h"
2009467b48Spatrick #include "llvm/ADT/SmallString.h"
2109467b48Spatrick #include "llvm/ADT/SmallVector.h"
2209467b48Spatrick #include "llvm/ADT/StringRef.h"
2309467b48Spatrick #include "llvm/ADT/Twine.h"
2409467b48Spatrick #include "llvm/Analysis/ConstantFolding.h"
2509467b48Spatrick #include "llvm/Analysis/EHPersonalities.h"
2609467b48Spatrick #include "llvm/CodeGen/MachineBasicBlock.h"
2709467b48Spatrick #include "llvm/CodeGen/MachineConstantPool.h"
2809467b48Spatrick #include "llvm/CodeGen/MachineFrameInfo.h"
2909467b48Spatrick #include "llvm/CodeGen/MachineInstr.h"
3009467b48Spatrick #include "llvm/CodeGen/MachineJumpTableInfo.h"
3109467b48Spatrick #include "llvm/CodeGen/MachineMemOperand.h"
3209467b48Spatrick #include "llvm/CodeGen/MachineModuleInfo.h"
3309467b48Spatrick #include "llvm/CodeGen/MachineRegisterInfo.h"
3409467b48Spatrick #include "llvm/CodeGen/PseudoSourceValue.h"
3509467b48Spatrick #include "llvm/CodeGen/TargetFrameLowering.h"
36097a140dSpatrick #include "llvm/CodeGen/TargetInstrInfo.h"
3709467b48Spatrick #include "llvm/CodeGen/TargetLowering.h"
3809467b48Spatrick #include "llvm/CodeGen/TargetRegisterInfo.h"
3909467b48Spatrick #include "llvm/CodeGen/TargetSubtargetInfo.h"
4009467b48Spatrick #include "llvm/CodeGen/WasmEHFuncInfo.h"
4109467b48Spatrick #include "llvm/CodeGen/WinEHFuncInfo.h"
4209467b48Spatrick #include "llvm/Config/llvm-config.h"
4309467b48Spatrick #include "llvm/IR/Attributes.h"
4409467b48Spatrick #include "llvm/IR/BasicBlock.h"
4509467b48Spatrick #include "llvm/IR/Constant.h"
4609467b48Spatrick #include "llvm/IR/DataLayout.h"
4709467b48Spatrick #include "llvm/IR/DerivedTypes.h"
4809467b48Spatrick #include "llvm/IR/Function.h"
4909467b48Spatrick #include "llvm/IR/GlobalValue.h"
5009467b48Spatrick #include "llvm/IR/Instruction.h"
5109467b48Spatrick #include "llvm/IR/Instructions.h"
5209467b48Spatrick #include "llvm/IR/Metadata.h"
5309467b48Spatrick #include "llvm/IR/Module.h"
5409467b48Spatrick #include "llvm/IR/ModuleSlotTracker.h"
5509467b48Spatrick #include "llvm/IR/Value.h"
5609467b48Spatrick #include "llvm/MC/MCContext.h"
5709467b48Spatrick #include "llvm/MC/MCSymbol.h"
5809467b48Spatrick #include "llvm/MC/SectionKind.h"
5909467b48Spatrick #include "llvm/Support/Casting.h"
6009467b48Spatrick #include "llvm/Support/CommandLine.h"
6109467b48Spatrick #include "llvm/Support/Compiler.h"
6209467b48Spatrick #include "llvm/Support/DOTGraphTraits.h"
6309467b48Spatrick #include "llvm/Support/ErrorHandling.h"
6409467b48Spatrick #include "llvm/Support/GraphWriter.h"
6509467b48Spatrick #include "llvm/Support/raw_ostream.h"
6609467b48Spatrick #include "llvm/Target/TargetMachine.h"
6709467b48Spatrick #include <algorithm>
6809467b48Spatrick #include <cassert>
6909467b48Spatrick #include <cstddef>
7009467b48Spatrick #include <cstdint>
7109467b48Spatrick #include <iterator>
7209467b48Spatrick #include <string>
73097a140dSpatrick #include <type_traits>
7409467b48Spatrick #include <utility>
7509467b48Spatrick #include <vector>
7609467b48Spatrick
77*d415bd75Srobert #include "LiveDebugValues/LiveDebugValues.h"
78*d415bd75Srobert
7909467b48Spatrick using namespace llvm;
8009467b48Spatrick
8109467b48Spatrick #define DEBUG_TYPE "codegen"
8209467b48Spatrick
8309467b48Spatrick static cl::opt<unsigned> AlignAllFunctions(
8409467b48Spatrick "align-all-functions",
8509467b48Spatrick cl::desc("Force the alignment of all functions in log2 format (e.g. 4 "
8609467b48Spatrick "means align on 16B boundaries)."),
8709467b48Spatrick cl::init(0), cl::Hidden);
8809467b48Spatrick
getPropertyName(MachineFunctionProperties::Property Prop)8909467b48Spatrick static const char *getPropertyName(MachineFunctionProperties::Property Prop) {
9009467b48Spatrick using P = MachineFunctionProperties::Property;
9109467b48Spatrick
92*d415bd75Srobert // clang-format off
9309467b48Spatrick switch(Prop) {
9409467b48Spatrick case P::FailedISel: return "FailedISel";
9509467b48Spatrick case P::IsSSA: return "IsSSA";
9609467b48Spatrick case P::Legalized: return "Legalized";
9709467b48Spatrick case P::NoPHIs: return "NoPHIs";
9809467b48Spatrick case P::NoVRegs: return "NoVRegs";
9909467b48Spatrick case P::RegBankSelected: return "RegBankSelected";
10009467b48Spatrick case P::Selected: return "Selected";
10109467b48Spatrick case P::TracksLiveness: return "TracksLiveness";
102097a140dSpatrick case P::TiedOpsRewritten: return "TiedOpsRewritten";
103*d415bd75Srobert case P::FailsVerification: return "FailsVerification";
104*d415bd75Srobert case P::TracksDebugUserValues: return "TracksDebugUserValues";
10509467b48Spatrick }
106*d415bd75Srobert // clang-format on
10709467b48Spatrick llvm_unreachable("Invalid machine function property");
10809467b48Spatrick }
10909467b48Spatrick
setUnsafeStackSize(const Function & F,MachineFrameInfo & FrameInfo)110*d415bd75Srobert void setUnsafeStackSize(const Function &F, MachineFrameInfo &FrameInfo) {
111*d415bd75Srobert if (!F.hasFnAttribute(Attribute::SafeStack))
112*d415bd75Srobert return;
113*d415bd75Srobert
114*d415bd75Srobert auto *Existing =
115*d415bd75Srobert dyn_cast_or_null<MDTuple>(F.getMetadata(LLVMContext::MD_annotation));
116*d415bd75Srobert
117*d415bd75Srobert if (!Existing || Existing->getNumOperands() != 2)
118*d415bd75Srobert return;
119*d415bd75Srobert
120*d415bd75Srobert auto *MetadataName = "unsafe-stack-size";
121*d415bd75Srobert if (auto &N = Existing->getOperand(0)) {
122*d415bd75Srobert if (cast<MDString>(N.get())->getString() == MetadataName) {
123*d415bd75Srobert if (auto &Op = Existing->getOperand(1)) {
124*d415bd75Srobert auto Val = mdconst::extract<ConstantInt>(Op)->getZExtValue();
125*d415bd75Srobert FrameInfo.setUnsafeStackSize(Val);
126*d415bd75Srobert }
127*d415bd75Srobert }
128*d415bd75Srobert }
129*d415bd75Srobert }
130*d415bd75Srobert
13109467b48Spatrick // Pin the vtable to this file.
anchor()13209467b48Spatrick void MachineFunction::Delegate::anchor() {}
13309467b48Spatrick
print(raw_ostream & OS) const13409467b48Spatrick void MachineFunctionProperties::print(raw_ostream &OS) const {
13509467b48Spatrick const char *Separator = "";
13609467b48Spatrick for (BitVector::size_type I = 0; I < Properties.size(); ++I) {
13709467b48Spatrick if (!Properties[I])
13809467b48Spatrick continue;
13909467b48Spatrick OS << Separator << getPropertyName(static_cast<Property>(I));
14009467b48Spatrick Separator = ", ";
14109467b48Spatrick }
14209467b48Spatrick }
14309467b48Spatrick
14409467b48Spatrick //===----------------------------------------------------------------------===//
14509467b48Spatrick // MachineFunction implementation
14609467b48Spatrick //===----------------------------------------------------------------------===//
14709467b48Spatrick
14809467b48Spatrick // Out-of-line virtual method.
14909467b48Spatrick MachineFunctionInfo::~MachineFunctionInfo() = default;
15009467b48Spatrick
deleteNode(MachineBasicBlock * MBB)15109467b48Spatrick void ilist_alloc_traits<MachineBasicBlock>::deleteNode(MachineBasicBlock *MBB) {
152*d415bd75Srobert MBB->getParent()->deleteMachineBasicBlock(MBB);
15309467b48Spatrick }
15409467b48Spatrick
getFnStackAlignment(const TargetSubtargetInfo * STI,const Function & F)155*d415bd75Srobert static inline Align getFnStackAlignment(const TargetSubtargetInfo *STI,
15609467b48Spatrick const Function &F) {
157*d415bd75Srobert if (auto MA = F.getFnStackAlign())
158*d415bd75Srobert return *MA;
159*d415bd75Srobert return STI->getFrameLowering()->getStackAlign();
16009467b48Spatrick }
16109467b48Spatrick
MachineFunction(Function & F,const LLVMTargetMachine & Target,const TargetSubtargetInfo & STI,unsigned FunctionNum,MachineModuleInfo & mmi)162097a140dSpatrick MachineFunction::MachineFunction(Function &F, const LLVMTargetMachine &Target,
16309467b48Spatrick const TargetSubtargetInfo &STI,
16409467b48Spatrick unsigned FunctionNum, MachineModuleInfo &mmi)
16509467b48Spatrick : F(F), Target(Target), STI(&STI), Ctx(mmi.getContext()), MMI(mmi) {
16609467b48Spatrick FunctionNumber = FunctionNum;
16709467b48Spatrick init();
16809467b48Spatrick }
16909467b48Spatrick
handleInsertion(MachineInstr & MI)17009467b48Spatrick void MachineFunction::handleInsertion(MachineInstr &MI) {
17109467b48Spatrick if (TheDelegate)
17209467b48Spatrick TheDelegate->MF_HandleInsertion(MI);
17309467b48Spatrick }
17409467b48Spatrick
handleRemoval(MachineInstr & MI)17509467b48Spatrick void MachineFunction::handleRemoval(MachineInstr &MI) {
17609467b48Spatrick if (TheDelegate)
17709467b48Spatrick TheDelegate->MF_HandleRemoval(MI);
17809467b48Spatrick }
17909467b48Spatrick
init()18009467b48Spatrick void MachineFunction::init() {
18109467b48Spatrick // Assume the function starts in SSA form with correct liveness.
18209467b48Spatrick Properties.set(MachineFunctionProperties::Property::IsSSA);
18309467b48Spatrick Properties.set(MachineFunctionProperties::Property::TracksLiveness);
18409467b48Spatrick if (STI->getRegisterInfo())
18509467b48Spatrick RegInfo = new (Allocator) MachineRegisterInfo(this);
18609467b48Spatrick else
18709467b48Spatrick RegInfo = nullptr;
18809467b48Spatrick
18909467b48Spatrick MFInfo = nullptr;
190*d415bd75Srobert
19109467b48Spatrick // We can realign the stack if the target supports it and the user hasn't
19209467b48Spatrick // explicitly asked us not to.
19309467b48Spatrick bool CanRealignSP = STI->getFrameLowering()->isStackRealignable() &&
19409467b48Spatrick !F.hasFnAttribute("no-realign-stack");
19509467b48Spatrick FrameInfo = new (Allocator) MachineFrameInfo(
19609467b48Spatrick getFnStackAlignment(STI, F), /*StackRealignable=*/CanRealignSP,
19709467b48Spatrick /*ForcedRealign=*/CanRealignSP &&
19809467b48Spatrick F.hasFnAttribute(Attribute::StackAlignment));
19909467b48Spatrick
200*d415bd75Srobert setUnsafeStackSize(F, *FrameInfo);
201*d415bd75Srobert
20209467b48Spatrick if (F.hasFnAttribute(Attribute::StackAlignment))
203097a140dSpatrick FrameInfo->ensureMaxAlignment(*F.getFnStackAlign());
20409467b48Spatrick
20509467b48Spatrick ConstantPool = new (Allocator) MachineConstantPool(getDataLayout());
20609467b48Spatrick Alignment = STI->getTargetLowering()->getMinFunctionAlignment();
20709467b48Spatrick
20809467b48Spatrick // FIXME: Shouldn't use pref alignment if explicit alignment is set on F.
20909467b48Spatrick // FIXME: Use Function::hasOptSize().
21009467b48Spatrick if (!F.hasFnAttribute(Attribute::OptimizeForSize))
21109467b48Spatrick Alignment = std::max(Alignment,
21209467b48Spatrick STI->getTargetLowering()->getPrefFunctionAlignment());
21309467b48Spatrick
21409467b48Spatrick if (AlignAllFunctions)
21509467b48Spatrick Alignment = Align(1ULL << AlignAllFunctions);
21609467b48Spatrick
21709467b48Spatrick JumpTableInfo = nullptr;
21809467b48Spatrick
21909467b48Spatrick if (isFuncletEHPersonality(classifyEHPersonality(
22009467b48Spatrick F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr))) {
22109467b48Spatrick WinEHInfo = new (Allocator) WinEHFuncInfo();
22209467b48Spatrick }
22309467b48Spatrick
22409467b48Spatrick if (isScopedEHPersonality(classifyEHPersonality(
22509467b48Spatrick F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr))) {
22609467b48Spatrick WasmEHInfo = new (Allocator) WasmEHFuncInfo();
22709467b48Spatrick }
22809467b48Spatrick
22909467b48Spatrick assert(Target.isCompatibleDataLayout(getDataLayout()) &&
23009467b48Spatrick "Can't create a MachineFunction using a Module with a "
23109467b48Spatrick "Target-incompatible DataLayout attached\n");
23209467b48Spatrick
233*d415bd75Srobert PSVManager = std::make_unique<PseudoSourceValueManager>(getTarget());
234*d415bd75Srobert }
235*d415bd75Srobert
initTargetMachineFunctionInfo(const TargetSubtargetInfo & STI)236*d415bd75Srobert void MachineFunction::initTargetMachineFunctionInfo(
237*d415bd75Srobert const TargetSubtargetInfo &STI) {
238*d415bd75Srobert assert(!MFInfo && "MachineFunctionInfo already set");
239*d415bd75Srobert MFInfo = Target.createMachineFunctionInfo(Allocator, F, &STI);
24009467b48Spatrick }
24109467b48Spatrick
~MachineFunction()24209467b48Spatrick MachineFunction::~MachineFunction() {
24309467b48Spatrick clear();
24409467b48Spatrick }
24509467b48Spatrick
clear()24609467b48Spatrick void MachineFunction::clear() {
24709467b48Spatrick Properties.reset();
24809467b48Spatrick // Don't call destructors on MachineInstr and MachineOperand. All of their
24909467b48Spatrick // memory comes from the BumpPtrAllocator which is about to be purged.
25009467b48Spatrick //
25109467b48Spatrick // Do call MachineBasicBlock destructors, it contains std::vectors.
25209467b48Spatrick for (iterator I = begin(), E = end(); I != E; I = BasicBlocks.erase(I))
25309467b48Spatrick I->Insts.clearAndLeakNodesUnsafely();
25409467b48Spatrick MBBNumbering.clear();
25509467b48Spatrick
25609467b48Spatrick InstructionRecycler.clear(Allocator);
25709467b48Spatrick OperandRecycler.clear(Allocator);
25809467b48Spatrick BasicBlockRecycler.clear(Allocator);
25909467b48Spatrick CodeViewAnnotations.clear();
26009467b48Spatrick VariableDbgInfos.clear();
26109467b48Spatrick if (RegInfo) {
26209467b48Spatrick RegInfo->~MachineRegisterInfo();
26309467b48Spatrick Allocator.Deallocate(RegInfo);
26409467b48Spatrick }
26509467b48Spatrick if (MFInfo) {
26609467b48Spatrick MFInfo->~MachineFunctionInfo();
26709467b48Spatrick Allocator.Deallocate(MFInfo);
26809467b48Spatrick }
26909467b48Spatrick
27009467b48Spatrick FrameInfo->~MachineFrameInfo();
27109467b48Spatrick Allocator.Deallocate(FrameInfo);
27209467b48Spatrick
27309467b48Spatrick ConstantPool->~MachineConstantPool();
27409467b48Spatrick Allocator.Deallocate(ConstantPool);
27509467b48Spatrick
27609467b48Spatrick if (JumpTableInfo) {
27709467b48Spatrick JumpTableInfo->~MachineJumpTableInfo();
27809467b48Spatrick Allocator.Deallocate(JumpTableInfo);
27909467b48Spatrick }
28009467b48Spatrick
28109467b48Spatrick if (WinEHInfo) {
28209467b48Spatrick WinEHInfo->~WinEHFuncInfo();
28309467b48Spatrick Allocator.Deallocate(WinEHInfo);
28409467b48Spatrick }
28509467b48Spatrick
28609467b48Spatrick if (WasmEHInfo) {
28709467b48Spatrick WasmEHInfo->~WasmEHFuncInfo();
28809467b48Spatrick Allocator.Deallocate(WasmEHInfo);
28909467b48Spatrick }
29009467b48Spatrick }
29109467b48Spatrick
getDataLayout() const29209467b48Spatrick const DataLayout &MachineFunction::getDataLayout() const {
29309467b48Spatrick return F.getParent()->getDataLayout();
29409467b48Spatrick }
29509467b48Spatrick
29609467b48Spatrick /// Get the JumpTableInfo for this function.
29709467b48Spatrick /// If it does not already exist, allocate one.
29809467b48Spatrick MachineJumpTableInfo *MachineFunction::
getOrCreateJumpTableInfo(unsigned EntryKind)29909467b48Spatrick getOrCreateJumpTableInfo(unsigned EntryKind) {
30009467b48Spatrick if (JumpTableInfo) return JumpTableInfo;
30109467b48Spatrick
30209467b48Spatrick JumpTableInfo = new (Allocator)
30309467b48Spatrick MachineJumpTableInfo((MachineJumpTableInfo::JTEntryKind)EntryKind);
30409467b48Spatrick return JumpTableInfo;
30509467b48Spatrick }
30609467b48Spatrick
getDenormalMode(const fltSemantics & FPType) const30709467b48Spatrick DenormalMode MachineFunction::getDenormalMode(const fltSemantics &FPType) const {
30873471bf0Spatrick return F.getDenormalMode(FPType);
30909467b48Spatrick }
31009467b48Spatrick
31109467b48Spatrick /// Should we be emitting segmented stack stuff for the function
shouldSplitStack() const31209467b48Spatrick bool MachineFunction::shouldSplitStack() const {
31309467b48Spatrick return getFunction().hasFnAttribute("split-stack");
31409467b48Spatrick }
31509467b48Spatrick
316*d415bd75Srobert [[nodiscard]] unsigned
addFrameInst(const MCCFIInstruction & Inst)31709467b48Spatrick MachineFunction::addFrameInst(const MCCFIInstruction &Inst) {
31809467b48Spatrick FrameInstructions.push_back(Inst);
31909467b48Spatrick return FrameInstructions.size() - 1;
32009467b48Spatrick }
32109467b48Spatrick
32209467b48Spatrick /// This discards all of the MachineBasicBlock numbers and recomputes them.
32309467b48Spatrick /// This guarantees that the MBB numbers are sequential, dense, and match the
32409467b48Spatrick /// ordering of the blocks within the function. If a specific MachineBasicBlock
32509467b48Spatrick /// is specified, only that block and those after it are renumbered.
RenumberBlocks(MachineBasicBlock * MBB)32609467b48Spatrick void MachineFunction::RenumberBlocks(MachineBasicBlock *MBB) {
32709467b48Spatrick if (empty()) { MBBNumbering.clear(); return; }
32809467b48Spatrick MachineFunction::iterator MBBI, E = end();
32909467b48Spatrick if (MBB == nullptr)
33009467b48Spatrick MBBI = begin();
33109467b48Spatrick else
33209467b48Spatrick MBBI = MBB->getIterator();
33309467b48Spatrick
33409467b48Spatrick // Figure out the block number this should have.
33509467b48Spatrick unsigned BlockNo = 0;
33609467b48Spatrick if (MBBI != begin())
33709467b48Spatrick BlockNo = std::prev(MBBI)->getNumber() + 1;
33809467b48Spatrick
33909467b48Spatrick for (; MBBI != E; ++MBBI, ++BlockNo) {
34009467b48Spatrick if (MBBI->getNumber() != (int)BlockNo) {
34109467b48Spatrick // Remove use of the old number.
34209467b48Spatrick if (MBBI->getNumber() != -1) {
34309467b48Spatrick assert(MBBNumbering[MBBI->getNumber()] == &*MBBI &&
34409467b48Spatrick "MBB number mismatch!");
34509467b48Spatrick MBBNumbering[MBBI->getNumber()] = nullptr;
34609467b48Spatrick }
34709467b48Spatrick
34809467b48Spatrick // If BlockNo is already taken, set that block's number to -1.
34909467b48Spatrick if (MBBNumbering[BlockNo])
35009467b48Spatrick MBBNumbering[BlockNo]->setNumber(-1);
35109467b48Spatrick
35209467b48Spatrick MBBNumbering[BlockNo] = &*MBBI;
35309467b48Spatrick MBBI->setNumber(BlockNo);
35409467b48Spatrick }
35509467b48Spatrick }
35609467b48Spatrick
35709467b48Spatrick // Okay, all the blocks are renumbered. If we have compactified the block
35809467b48Spatrick // numbering, shrink MBBNumbering now.
35909467b48Spatrick assert(BlockNo <= MBBNumbering.size() && "Mismatch!");
36009467b48Spatrick MBBNumbering.resize(BlockNo);
36109467b48Spatrick }
36209467b48Spatrick
363097a140dSpatrick /// This method iterates over the basic blocks and assigns their IsBeginSection
364097a140dSpatrick /// and IsEndSection fields. This must be called after MBB layout is finalized
365097a140dSpatrick /// and the SectionID's are assigned to MBBs.
assignBeginEndSections()366097a140dSpatrick void MachineFunction::assignBeginEndSections() {
367097a140dSpatrick front().setIsBeginSection();
368097a140dSpatrick auto CurrentSectionID = front().getSectionID();
369097a140dSpatrick for (auto MBBI = std::next(begin()), E = end(); MBBI != E; ++MBBI) {
370097a140dSpatrick if (MBBI->getSectionID() == CurrentSectionID)
371097a140dSpatrick continue;
372097a140dSpatrick MBBI->setIsBeginSection();
373097a140dSpatrick std::prev(MBBI)->setIsEndSection();
374097a140dSpatrick CurrentSectionID = MBBI->getSectionID();
375097a140dSpatrick }
376097a140dSpatrick back().setIsEndSection();
377097a140dSpatrick }
378097a140dSpatrick
37909467b48Spatrick /// Allocate a new MachineInstr. Use this instead of `new MachineInstr'.
CreateMachineInstr(const MCInstrDesc & MCID,DebugLoc DL,bool NoImplicit)38009467b48Spatrick MachineInstr *MachineFunction::CreateMachineInstr(const MCInstrDesc &MCID,
381*d415bd75Srobert DebugLoc DL,
38273471bf0Spatrick bool NoImplicit) {
38309467b48Spatrick return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
384*d415bd75Srobert MachineInstr(*this, MCID, std::move(DL), NoImplicit);
38509467b48Spatrick }
38609467b48Spatrick
38709467b48Spatrick /// Create a new MachineInstr which is a copy of the 'Orig' instruction,
38809467b48Spatrick /// identical in all ways except the instruction has no parent, prev, or next.
38909467b48Spatrick MachineInstr *
CloneMachineInstr(const MachineInstr * Orig)39009467b48Spatrick MachineFunction::CloneMachineInstr(const MachineInstr *Orig) {
39109467b48Spatrick return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
39209467b48Spatrick MachineInstr(*this, *Orig);
39309467b48Spatrick }
39409467b48Spatrick
cloneMachineInstrBundle(MachineBasicBlock & MBB,MachineBasicBlock::iterator InsertBefore,const MachineInstr & Orig)395*d415bd75Srobert MachineInstr &MachineFunction::cloneMachineInstrBundle(
396*d415bd75Srobert MachineBasicBlock &MBB, MachineBasicBlock::iterator InsertBefore,
397*d415bd75Srobert const MachineInstr &Orig) {
39809467b48Spatrick MachineInstr *FirstClone = nullptr;
39909467b48Spatrick MachineBasicBlock::const_instr_iterator I = Orig.getIterator();
40009467b48Spatrick while (true) {
40109467b48Spatrick MachineInstr *Cloned = CloneMachineInstr(&*I);
40209467b48Spatrick MBB.insert(InsertBefore, Cloned);
40309467b48Spatrick if (FirstClone == nullptr) {
40409467b48Spatrick FirstClone = Cloned;
40509467b48Spatrick } else {
40609467b48Spatrick Cloned->bundleWithPred();
40709467b48Spatrick }
40809467b48Spatrick
40909467b48Spatrick if (!I->isBundledWithSucc())
41009467b48Spatrick break;
41109467b48Spatrick ++I;
41209467b48Spatrick }
413097a140dSpatrick // Copy over call site info to the cloned instruction if needed. If Orig is in
414097a140dSpatrick // a bundle, copyCallSiteInfo takes care of finding the call instruction in
415097a140dSpatrick // the bundle.
416097a140dSpatrick if (Orig.shouldUpdateCallSiteInfo())
417097a140dSpatrick copyCallSiteInfo(&Orig, FirstClone);
41809467b48Spatrick return *FirstClone;
41909467b48Spatrick }
42009467b48Spatrick
42109467b48Spatrick /// Delete the given MachineInstr.
42209467b48Spatrick ///
42309467b48Spatrick /// This function also serves as the MachineInstr destructor - the real
42409467b48Spatrick /// ~MachineInstr() destructor must be empty.
deleteMachineInstr(MachineInstr * MI)425*d415bd75Srobert void MachineFunction::deleteMachineInstr(MachineInstr *MI) {
42609467b48Spatrick // Verify that a call site info is at valid state. This assertion should
42709467b48Spatrick // be triggered during the implementation of support for the
42809467b48Spatrick // call site info of a new architecture. If the assertion is triggered,
42909467b48Spatrick // back trace will tell where to insert a call to updateCallSiteInfo().
430097a140dSpatrick assert((!MI->isCandidateForCallSiteEntry() ||
43109467b48Spatrick CallSitesInfo.find(MI) == CallSitesInfo.end()) &&
43209467b48Spatrick "Call site info was not updated!");
43309467b48Spatrick // Strip it for parts. The operand array and the MI object itself are
43409467b48Spatrick // independently recyclable.
43509467b48Spatrick if (MI->Operands)
43609467b48Spatrick deallocateOperandArray(MI->CapOperands, MI->Operands);
43709467b48Spatrick // Don't call ~MachineInstr() which must be trivial anyway because
43809467b48Spatrick // ~MachineFunction drops whole lists of MachineInstrs wihout calling their
43909467b48Spatrick // destructors.
44009467b48Spatrick InstructionRecycler.Deallocate(Allocator, MI);
44109467b48Spatrick }
44209467b48Spatrick
44309467b48Spatrick /// Allocate a new MachineBasicBlock. Use this instead of
44409467b48Spatrick /// `new MachineBasicBlock'.
44509467b48Spatrick MachineBasicBlock *
CreateMachineBasicBlock(const BasicBlock * bb)44609467b48Spatrick MachineFunction::CreateMachineBasicBlock(const BasicBlock *bb) {
447*d415bd75Srobert MachineBasicBlock *MBB =
448*d415bd75Srobert new (BasicBlockRecycler.Allocate<MachineBasicBlock>(Allocator))
44909467b48Spatrick MachineBasicBlock(*this, bb);
450*d415bd75Srobert // Set BBID for `-basic-block=sections=labels` and
451*d415bd75Srobert // `-basic-block-sections=list` to allow robust mapping of profiles to basic
452*d415bd75Srobert // blocks.
453*d415bd75Srobert if (Target.getBBSectionsType() == BasicBlockSection::Labels ||
454*d415bd75Srobert Target.getBBSectionsType() == BasicBlockSection::List)
455*d415bd75Srobert MBB->setBBID(NextBBID++);
456*d415bd75Srobert return MBB;
45709467b48Spatrick }
45809467b48Spatrick
45909467b48Spatrick /// Delete the given MachineBasicBlock.
deleteMachineBasicBlock(MachineBasicBlock * MBB)460*d415bd75Srobert void MachineFunction::deleteMachineBasicBlock(MachineBasicBlock *MBB) {
46109467b48Spatrick assert(MBB->getParent() == this && "MBB parent mismatch!");
46273471bf0Spatrick // Clean up any references to MBB in jump tables before deleting it.
46373471bf0Spatrick if (JumpTableInfo)
46473471bf0Spatrick JumpTableInfo->RemoveMBBFromJumpTables(MBB);
46509467b48Spatrick MBB->~MachineBasicBlock();
46609467b48Spatrick BasicBlockRecycler.Deallocate(Allocator, MBB);
46709467b48Spatrick }
46809467b48Spatrick
getMachineMemOperand(MachinePointerInfo PtrInfo,MachineMemOperand::Flags f,uint64_t s,Align base_alignment,const AAMDNodes & AAInfo,const MDNode * Ranges,SyncScope::ID SSID,AtomicOrdering Ordering,AtomicOrdering FailureOrdering)46909467b48Spatrick MachineMemOperand *MachineFunction::getMachineMemOperand(
47009467b48Spatrick MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s,
471097a140dSpatrick Align base_alignment, const AAMDNodes &AAInfo, const MDNode *Ranges,
47209467b48Spatrick SyncScope::ID SSID, AtomicOrdering Ordering,
47309467b48Spatrick AtomicOrdering FailureOrdering) {
47409467b48Spatrick return new (Allocator)
47509467b48Spatrick MachineMemOperand(PtrInfo, f, s, base_alignment, AAInfo, Ranges,
47609467b48Spatrick SSID, Ordering, FailureOrdering);
47709467b48Spatrick }
47809467b48Spatrick
getMachineMemOperand(MachinePointerInfo PtrInfo,MachineMemOperand::Flags f,LLT MemTy,Align base_alignment,const AAMDNodes & AAInfo,const MDNode * Ranges,SyncScope::ID SSID,AtomicOrdering Ordering,AtomicOrdering FailureOrdering)47973471bf0Spatrick MachineMemOperand *MachineFunction::getMachineMemOperand(
48073471bf0Spatrick MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy,
48173471bf0Spatrick Align base_alignment, const AAMDNodes &AAInfo, const MDNode *Ranges,
48273471bf0Spatrick SyncScope::ID SSID, AtomicOrdering Ordering,
48373471bf0Spatrick AtomicOrdering FailureOrdering) {
48473471bf0Spatrick return new (Allocator)
48573471bf0Spatrick MachineMemOperand(PtrInfo, f, MemTy, base_alignment, AAInfo, Ranges, SSID,
48673471bf0Spatrick Ordering, FailureOrdering);
48773471bf0Spatrick }
48873471bf0Spatrick
getMachineMemOperand(const MachineMemOperand * MMO,const MachinePointerInfo & PtrInfo,uint64_t Size)48973471bf0Spatrick MachineMemOperand *MachineFunction::getMachineMemOperand(
49073471bf0Spatrick const MachineMemOperand *MMO, const MachinePointerInfo &PtrInfo, uint64_t Size) {
49173471bf0Spatrick return new (Allocator)
49273471bf0Spatrick MachineMemOperand(PtrInfo, MMO->getFlags(), Size, MMO->getBaseAlign(),
49373471bf0Spatrick AAMDNodes(), nullptr, MMO->getSyncScopeID(),
49473471bf0Spatrick MMO->getSuccessOrdering(), MMO->getFailureOrdering());
49573471bf0Spatrick }
49673471bf0Spatrick
getMachineMemOperand(const MachineMemOperand * MMO,const MachinePointerInfo & PtrInfo,LLT Ty)49773471bf0Spatrick MachineMemOperand *MachineFunction::getMachineMemOperand(
49873471bf0Spatrick const MachineMemOperand *MMO, const MachinePointerInfo &PtrInfo, LLT Ty) {
49973471bf0Spatrick return new (Allocator)
50073471bf0Spatrick MachineMemOperand(PtrInfo, MMO->getFlags(), Ty, MMO->getBaseAlign(),
50173471bf0Spatrick AAMDNodes(), nullptr, MMO->getSyncScopeID(),
50273471bf0Spatrick MMO->getSuccessOrdering(), MMO->getFailureOrdering());
50373471bf0Spatrick }
50473471bf0Spatrick
50509467b48Spatrick MachineMemOperand *
getMachineMemOperand(const MachineMemOperand * MMO,int64_t Offset,LLT Ty)50609467b48Spatrick MachineFunction::getMachineMemOperand(const MachineMemOperand *MMO,
50773471bf0Spatrick int64_t Offset, LLT Ty) {
50809467b48Spatrick const MachinePointerInfo &PtrInfo = MMO->getPointerInfo();
50909467b48Spatrick
51009467b48Spatrick // If there is no pointer value, the offset isn't tracked so we need to adjust
51109467b48Spatrick // the base alignment.
512097a140dSpatrick Align Alignment = PtrInfo.V.isNull()
513097a140dSpatrick ? commonAlignment(MMO->getBaseAlign(), Offset)
514097a140dSpatrick : MMO->getBaseAlign();
51509467b48Spatrick
51673471bf0Spatrick // Do not preserve ranges, since we don't necessarily know what the high bits
51773471bf0Spatrick // are anymore.
51873471bf0Spatrick return new (Allocator) MachineMemOperand(
51973471bf0Spatrick PtrInfo.getWithOffset(Offset), MMO->getFlags(), Ty, Alignment,
52073471bf0Spatrick MMO->getAAInfo(), nullptr, MMO->getSyncScopeID(),
52173471bf0Spatrick MMO->getSuccessOrdering(), MMO->getFailureOrdering());
52209467b48Spatrick }
52309467b48Spatrick
52409467b48Spatrick MachineMemOperand *
getMachineMemOperand(const MachineMemOperand * MMO,const AAMDNodes & AAInfo)52509467b48Spatrick MachineFunction::getMachineMemOperand(const MachineMemOperand *MMO,
52609467b48Spatrick const AAMDNodes &AAInfo) {
52709467b48Spatrick MachinePointerInfo MPI = MMO->getValue() ?
52809467b48Spatrick MachinePointerInfo(MMO->getValue(), MMO->getOffset()) :
52909467b48Spatrick MachinePointerInfo(MMO->getPseudoValue(), MMO->getOffset());
53009467b48Spatrick
531097a140dSpatrick return new (Allocator) MachineMemOperand(
532097a140dSpatrick MPI, MMO->getFlags(), MMO->getSize(), MMO->getBaseAlign(), AAInfo,
53373471bf0Spatrick MMO->getRanges(), MMO->getSyncScopeID(), MMO->getSuccessOrdering(),
534097a140dSpatrick MMO->getFailureOrdering());
53509467b48Spatrick }
53609467b48Spatrick
53709467b48Spatrick MachineMemOperand *
getMachineMemOperand(const MachineMemOperand * MMO,MachineMemOperand::Flags Flags)53809467b48Spatrick MachineFunction::getMachineMemOperand(const MachineMemOperand *MMO,
53909467b48Spatrick MachineMemOperand::Flags Flags) {
54009467b48Spatrick return new (Allocator) MachineMemOperand(
541097a140dSpatrick MMO->getPointerInfo(), Flags, MMO->getSize(), MMO->getBaseAlign(),
54209467b48Spatrick MMO->getAAInfo(), MMO->getRanges(), MMO->getSyncScopeID(),
54373471bf0Spatrick MMO->getSuccessOrdering(), MMO->getFailureOrdering());
54409467b48Spatrick }
54509467b48Spatrick
createMIExtraInfo(ArrayRef<MachineMemOperand * > MMOs,MCSymbol * PreInstrSymbol,MCSymbol * PostInstrSymbol,MDNode * HeapAllocMarker,MDNode * PCSections,uint32_t CFIType)54609467b48Spatrick MachineInstr::ExtraInfo *MachineFunction::createMIExtraInfo(
54709467b48Spatrick ArrayRef<MachineMemOperand *> MMOs, MCSymbol *PreInstrSymbol,
548*d415bd75Srobert MCSymbol *PostInstrSymbol, MDNode *HeapAllocMarker, MDNode *PCSections,
549*d415bd75Srobert uint32_t CFIType) {
55009467b48Spatrick return MachineInstr::ExtraInfo::create(Allocator, MMOs, PreInstrSymbol,
551*d415bd75Srobert PostInstrSymbol, HeapAllocMarker,
552*d415bd75Srobert PCSections, CFIType);
55309467b48Spatrick }
55409467b48Spatrick
createExternalSymbolName(StringRef Name)55509467b48Spatrick const char *MachineFunction::createExternalSymbolName(StringRef Name) {
55609467b48Spatrick char *Dest = Allocator.Allocate<char>(Name.size() + 1);
55709467b48Spatrick llvm::copy(Name, Dest);
55809467b48Spatrick Dest[Name.size()] = 0;
55909467b48Spatrick return Dest;
56009467b48Spatrick }
56109467b48Spatrick
allocateRegMask()56209467b48Spatrick uint32_t *MachineFunction::allocateRegMask() {
56309467b48Spatrick unsigned NumRegs = getSubtarget().getRegisterInfo()->getNumRegs();
56409467b48Spatrick unsigned Size = MachineOperand::getRegMaskSize(NumRegs);
56509467b48Spatrick uint32_t *Mask = Allocator.Allocate<uint32_t>(Size);
56609467b48Spatrick memset(Mask, 0, Size * sizeof(Mask[0]));
56709467b48Spatrick return Mask;
56809467b48Spatrick }
56909467b48Spatrick
allocateShuffleMask(ArrayRef<int> Mask)57009467b48Spatrick ArrayRef<int> MachineFunction::allocateShuffleMask(ArrayRef<int> Mask) {
57109467b48Spatrick int* AllocMask = Allocator.Allocate<int>(Mask.size());
57209467b48Spatrick copy(Mask, AllocMask);
57309467b48Spatrick return {AllocMask, Mask.size()};
57409467b48Spatrick }
57509467b48Spatrick
57609467b48Spatrick #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
dump() const57709467b48Spatrick LLVM_DUMP_METHOD void MachineFunction::dump() const {
57809467b48Spatrick print(dbgs());
57909467b48Spatrick }
58009467b48Spatrick #endif
58109467b48Spatrick
getName() const58209467b48Spatrick StringRef MachineFunction::getName() const {
58309467b48Spatrick return getFunction().getName();
58409467b48Spatrick }
58509467b48Spatrick
print(raw_ostream & OS,const SlotIndexes * Indexes) const58609467b48Spatrick void MachineFunction::print(raw_ostream &OS, const SlotIndexes *Indexes) const {
58709467b48Spatrick OS << "# Machine code for function " << getName() << ": ";
58809467b48Spatrick getProperties().print(OS);
58909467b48Spatrick OS << '\n';
59009467b48Spatrick
59109467b48Spatrick // Print Frame Information
59209467b48Spatrick FrameInfo->print(*this, OS);
59309467b48Spatrick
59409467b48Spatrick // Print JumpTable Information
59509467b48Spatrick if (JumpTableInfo)
59609467b48Spatrick JumpTableInfo->print(OS);
59709467b48Spatrick
59809467b48Spatrick // Print Constant Pool
59909467b48Spatrick ConstantPool->print(OS);
60009467b48Spatrick
60109467b48Spatrick const TargetRegisterInfo *TRI = getSubtarget().getRegisterInfo();
60209467b48Spatrick
60309467b48Spatrick if (RegInfo && !RegInfo->livein_empty()) {
60409467b48Spatrick OS << "Function Live Ins: ";
60509467b48Spatrick for (MachineRegisterInfo::livein_iterator
60609467b48Spatrick I = RegInfo->livein_begin(), E = RegInfo->livein_end(); I != E; ++I) {
60709467b48Spatrick OS << printReg(I->first, TRI);
60809467b48Spatrick if (I->second)
60909467b48Spatrick OS << " in " << printReg(I->second, TRI);
61009467b48Spatrick if (std::next(I) != E)
61109467b48Spatrick OS << ", ";
61209467b48Spatrick }
61309467b48Spatrick OS << '\n';
61409467b48Spatrick }
61509467b48Spatrick
61609467b48Spatrick ModuleSlotTracker MST(getFunction().getParent());
61709467b48Spatrick MST.incorporateFunction(getFunction());
61809467b48Spatrick for (const auto &BB : *this) {
61909467b48Spatrick OS << '\n';
62009467b48Spatrick // If we print the whole function, print it at its most verbose level.
62109467b48Spatrick BB.print(OS, MST, Indexes, /*IsStandalone=*/true);
62209467b48Spatrick }
62309467b48Spatrick
62409467b48Spatrick OS << "\n# End machine code for function " << getName() << ".\n\n";
62509467b48Spatrick }
62609467b48Spatrick
62709467b48Spatrick /// True if this function needs frame moves for debug or exceptions.
needsFrameMoves() const62809467b48Spatrick bool MachineFunction::needsFrameMoves() const {
62909467b48Spatrick return getMMI().hasDebugInfo() ||
63009467b48Spatrick getTarget().Options.ForceDwarfFrameSection ||
63109467b48Spatrick F.needsUnwindTableEntry();
63209467b48Spatrick }
63309467b48Spatrick
63409467b48Spatrick namespace llvm {
63509467b48Spatrick
63609467b48Spatrick template<>
63709467b48Spatrick struct DOTGraphTraits<const MachineFunction*> : public DefaultDOTGraphTraits {
DOTGraphTraitsllvm::DOTGraphTraits63809467b48Spatrick DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {}
63909467b48Spatrick
getGraphNamellvm::DOTGraphTraits64009467b48Spatrick static std::string getGraphName(const MachineFunction *F) {
64109467b48Spatrick return ("CFG for '" + F->getName() + "' function").str();
64209467b48Spatrick }
64309467b48Spatrick
getNodeLabelllvm::DOTGraphTraits64409467b48Spatrick std::string getNodeLabel(const MachineBasicBlock *Node,
64509467b48Spatrick const MachineFunction *Graph) {
64609467b48Spatrick std::string OutStr;
64709467b48Spatrick {
64809467b48Spatrick raw_string_ostream OSS(OutStr);
64909467b48Spatrick
65009467b48Spatrick if (isSimple()) {
65109467b48Spatrick OSS << printMBBReference(*Node);
65209467b48Spatrick if (const BasicBlock *BB = Node->getBasicBlock())
65309467b48Spatrick OSS << ": " << BB->getName();
65409467b48Spatrick } else
65509467b48Spatrick Node->print(OSS);
65609467b48Spatrick }
65709467b48Spatrick
65809467b48Spatrick if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
65909467b48Spatrick
66009467b48Spatrick // Process string output to make it nicer...
66109467b48Spatrick for (unsigned i = 0; i != OutStr.length(); ++i)
66209467b48Spatrick if (OutStr[i] == '\n') { // Left justify
66309467b48Spatrick OutStr[i] = '\\';
66409467b48Spatrick OutStr.insert(OutStr.begin()+i+1, 'l');
66509467b48Spatrick }
66609467b48Spatrick return OutStr;
66709467b48Spatrick }
66809467b48Spatrick };
66909467b48Spatrick
67009467b48Spatrick } // end namespace llvm
67109467b48Spatrick
viewCFG() const67209467b48Spatrick void MachineFunction::viewCFG() const
67309467b48Spatrick {
67409467b48Spatrick #ifndef NDEBUG
67509467b48Spatrick ViewGraph(this, "mf" + getName());
67609467b48Spatrick #else
67709467b48Spatrick errs() << "MachineFunction::viewCFG is only available in debug builds on "
67809467b48Spatrick << "systems with Graphviz or gv!\n";
67909467b48Spatrick #endif // NDEBUG
68009467b48Spatrick }
68109467b48Spatrick
viewCFGOnly() const68209467b48Spatrick void MachineFunction::viewCFGOnly() const
68309467b48Spatrick {
68409467b48Spatrick #ifndef NDEBUG
68509467b48Spatrick ViewGraph(this, "mf" + getName(), true);
68609467b48Spatrick #else
68709467b48Spatrick errs() << "MachineFunction::viewCFGOnly is only available in debug builds on "
68809467b48Spatrick << "systems with Graphviz or gv!\n";
68909467b48Spatrick #endif // NDEBUG
69009467b48Spatrick }
69109467b48Spatrick
69209467b48Spatrick /// Add the specified physical register as a live-in value and
69309467b48Spatrick /// create a corresponding virtual register for it.
addLiveIn(MCRegister PReg,const TargetRegisterClass * RC)694097a140dSpatrick Register MachineFunction::addLiveIn(MCRegister PReg,
69509467b48Spatrick const TargetRegisterClass *RC) {
69609467b48Spatrick MachineRegisterInfo &MRI = getRegInfo();
697097a140dSpatrick Register VReg = MRI.getLiveInVirtReg(PReg);
69809467b48Spatrick if (VReg) {
69909467b48Spatrick const TargetRegisterClass *VRegRC = MRI.getRegClass(VReg);
70009467b48Spatrick (void)VRegRC;
70109467b48Spatrick // A physical register can be added several times.
70209467b48Spatrick // Between two calls, the register class of the related virtual register
70309467b48Spatrick // may have been constrained to match some operation constraints.
70409467b48Spatrick // In that case, check that the current register class includes the
70509467b48Spatrick // physical register and is a sub class of the specified RC.
70609467b48Spatrick assert((VRegRC == RC || (VRegRC->contains(PReg) &&
70709467b48Spatrick RC->hasSubClassEq(VRegRC))) &&
70809467b48Spatrick "Register class mismatch!");
70909467b48Spatrick return VReg;
71009467b48Spatrick }
71109467b48Spatrick VReg = MRI.createVirtualRegister(RC);
71209467b48Spatrick MRI.addLiveIn(PReg, VReg);
71309467b48Spatrick return VReg;
71409467b48Spatrick }
71509467b48Spatrick
71609467b48Spatrick /// Return the MCSymbol for the specified non-empty jump table.
71709467b48Spatrick /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
71809467b48Spatrick /// normal 'L' label is returned.
getJTISymbol(unsigned JTI,MCContext & Ctx,bool isLinkerPrivate) const71909467b48Spatrick MCSymbol *MachineFunction::getJTISymbol(unsigned JTI, MCContext &Ctx,
72009467b48Spatrick bool isLinkerPrivate) const {
72109467b48Spatrick const DataLayout &DL = getDataLayout();
72209467b48Spatrick assert(JumpTableInfo && "No jump tables");
72309467b48Spatrick assert(JTI < JumpTableInfo->getJumpTables().size() && "Invalid JTI!");
72409467b48Spatrick
72509467b48Spatrick StringRef Prefix = isLinkerPrivate ? DL.getLinkerPrivateGlobalPrefix()
72609467b48Spatrick : DL.getPrivateGlobalPrefix();
72709467b48Spatrick SmallString<60> Name;
72809467b48Spatrick raw_svector_ostream(Name)
72909467b48Spatrick << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
73009467b48Spatrick return Ctx.getOrCreateSymbol(Name);
73109467b48Spatrick }
73209467b48Spatrick
73309467b48Spatrick /// Return a function-local symbol to represent the PIC base.
getPICBaseSymbol() const73409467b48Spatrick MCSymbol *MachineFunction::getPICBaseSymbol() const {
73509467b48Spatrick const DataLayout &DL = getDataLayout();
73609467b48Spatrick return Ctx.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
73709467b48Spatrick Twine(getFunctionNumber()) + "$pb");
73809467b48Spatrick }
73909467b48Spatrick
74009467b48Spatrick /// \name Exception Handling
74109467b48Spatrick /// \{
74209467b48Spatrick
74309467b48Spatrick LandingPadInfo &
getOrCreateLandingPadInfo(MachineBasicBlock * LandingPad)74409467b48Spatrick MachineFunction::getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad) {
74509467b48Spatrick unsigned N = LandingPads.size();
74609467b48Spatrick for (unsigned i = 0; i < N; ++i) {
74709467b48Spatrick LandingPadInfo &LP = LandingPads[i];
74809467b48Spatrick if (LP.LandingPadBlock == LandingPad)
74909467b48Spatrick return LP;
75009467b48Spatrick }
75109467b48Spatrick
75209467b48Spatrick LandingPads.push_back(LandingPadInfo(LandingPad));
75309467b48Spatrick return LandingPads[N];
75409467b48Spatrick }
75509467b48Spatrick
addInvoke(MachineBasicBlock * LandingPad,MCSymbol * BeginLabel,MCSymbol * EndLabel)75609467b48Spatrick void MachineFunction::addInvoke(MachineBasicBlock *LandingPad,
75709467b48Spatrick MCSymbol *BeginLabel, MCSymbol *EndLabel) {
75809467b48Spatrick LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
75909467b48Spatrick LP.BeginLabels.push_back(BeginLabel);
76009467b48Spatrick LP.EndLabels.push_back(EndLabel);
76109467b48Spatrick }
76209467b48Spatrick
addLandingPad(MachineBasicBlock * LandingPad)76309467b48Spatrick MCSymbol *MachineFunction::addLandingPad(MachineBasicBlock *LandingPad) {
76409467b48Spatrick MCSymbol *LandingPadLabel = Ctx.createTempSymbol();
76509467b48Spatrick LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
76609467b48Spatrick LP.LandingPadLabel = LandingPadLabel;
76709467b48Spatrick
76809467b48Spatrick const Instruction *FirstI = LandingPad->getBasicBlock()->getFirstNonPHI();
76909467b48Spatrick if (const auto *LPI = dyn_cast<LandingPadInst>(FirstI)) {
770*d415bd75Srobert // If there's no typeid list specified, then "cleanup" is implicit.
771*d415bd75Srobert // Otherwise, id 0 is reserved for the cleanup action.
772*d415bd75Srobert if (LPI->isCleanup() && LPI->getNumClauses() != 0)
773*d415bd75Srobert LP.TypeIds.push_back(0);
77409467b48Spatrick
77509467b48Spatrick // FIXME: New EH - Add the clauses in reverse order. This isn't 100%
77609467b48Spatrick // correct, but we need to do it this way because of how the DWARF EH
77709467b48Spatrick // emitter processes the clauses.
77809467b48Spatrick for (unsigned I = LPI->getNumClauses(); I != 0; --I) {
77909467b48Spatrick Value *Val = LPI->getClause(I - 1);
78009467b48Spatrick if (LPI->isCatch(I - 1)) {
781*d415bd75Srobert LP.TypeIds.push_back(
782*d415bd75Srobert getTypeIDFor(dyn_cast<GlobalValue>(Val->stripPointerCasts())));
78309467b48Spatrick } else {
78409467b48Spatrick // Add filters in a list.
78509467b48Spatrick auto *CVal = cast<Constant>(Val);
786*d415bd75Srobert SmallVector<unsigned, 4> FilterList;
787*d415bd75Srobert for (const Use &U : CVal->operands())
788*d415bd75Srobert FilterList.push_back(
789*d415bd75Srobert getTypeIDFor(cast<GlobalValue>(U->stripPointerCasts())));
79009467b48Spatrick
791*d415bd75Srobert LP.TypeIds.push_back(getFilterIDFor(FilterList));
79209467b48Spatrick }
79309467b48Spatrick }
79409467b48Spatrick
79509467b48Spatrick } else if (const auto *CPI = dyn_cast<CatchPadInst>(FirstI)) {
796*d415bd75Srobert for (unsigned I = CPI->arg_size(); I != 0; --I) {
797*d415bd75Srobert auto *TypeInfo =
798*d415bd75Srobert dyn_cast<GlobalValue>(CPI->getArgOperand(I - 1)->stripPointerCasts());
799*d415bd75Srobert LP.TypeIds.push_back(getTypeIDFor(TypeInfo));
80009467b48Spatrick }
80109467b48Spatrick
80209467b48Spatrick } else {
80309467b48Spatrick assert(isa<CleanupPadInst>(FirstI) && "Invalid landingpad!");
80409467b48Spatrick }
80509467b48Spatrick
80609467b48Spatrick return LandingPadLabel;
80709467b48Spatrick }
80809467b48Spatrick
setCallSiteLandingPad(MCSymbol * Sym,ArrayRef<unsigned> Sites)80909467b48Spatrick void MachineFunction::setCallSiteLandingPad(MCSymbol *Sym,
81009467b48Spatrick ArrayRef<unsigned> Sites) {
81109467b48Spatrick LPadToCallSiteMap[Sym].append(Sites.begin(), Sites.end());
81209467b48Spatrick }
81309467b48Spatrick
getTypeIDFor(const GlobalValue * TI)81409467b48Spatrick unsigned MachineFunction::getTypeIDFor(const GlobalValue *TI) {
81509467b48Spatrick for (unsigned i = 0, N = TypeInfos.size(); i != N; ++i)
81609467b48Spatrick if (TypeInfos[i] == TI) return i + 1;
81709467b48Spatrick
81809467b48Spatrick TypeInfos.push_back(TI);
81909467b48Spatrick return TypeInfos.size();
82009467b48Spatrick }
82109467b48Spatrick
getFilterIDFor(ArrayRef<unsigned> TyIds)822*d415bd75Srobert int MachineFunction::getFilterIDFor(ArrayRef<unsigned> TyIds) {
82309467b48Spatrick // If the new filter coincides with the tail of an existing filter, then
82409467b48Spatrick // re-use the existing filter. Folding filters more than this requires
82509467b48Spatrick // re-ordering filters and/or their elements - probably not worth it.
82673471bf0Spatrick for (unsigned i : FilterEnds) {
82773471bf0Spatrick unsigned j = TyIds.size();
82809467b48Spatrick
82909467b48Spatrick while (i && j)
83009467b48Spatrick if (FilterIds[--i] != TyIds[--j])
83109467b48Spatrick goto try_next;
83209467b48Spatrick
83309467b48Spatrick if (!j)
83409467b48Spatrick // The new filter coincides with range [i, end) of the existing filter.
83509467b48Spatrick return -(1 + i);
83609467b48Spatrick
83709467b48Spatrick try_next:;
83809467b48Spatrick }
83909467b48Spatrick
84009467b48Spatrick // Add the new filter.
84109467b48Spatrick int FilterID = -(1 + FilterIds.size());
84209467b48Spatrick FilterIds.reserve(FilterIds.size() + TyIds.size() + 1);
84373471bf0Spatrick llvm::append_range(FilterIds, TyIds);
84409467b48Spatrick FilterEnds.push_back(FilterIds.size());
84509467b48Spatrick FilterIds.push_back(0); // terminator
84609467b48Spatrick return FilterID;
84709467b48Spatrick }
84809467b48Spatrick
84909467b48Spatrick MachineFunction::CallSiteInfoMap::iterator
getCallSiteInfo(const MachineInstr * MI)85009467b48Spatrick MachineFunction::getCallSiteInfo(const MachineInstr *MI) {
851097a140dSpatrick assert(MI->isCandidateForCallSiteEntry() &&
852097a140dSpatrick "Call site info refers only to call (MI) candidates");
85309467b48Spatrick
854097a140dSpatrick if (!Target.Options.EmitCallSiteInfo)
85509467b48Spatrick return CallSitesInfo.end();
85609467b48Spatrick return CallSitesInfo.find(MI);
85709467b48Spatrick }
85809467b48Spatrick
859097a140dSpatrick /// Return the call machine instruction or find a call within bundle.
getCallInstr(const MachineInstr * MI)860097a140dSpatrick static const MachineInstr *getCallInstr(const MachineInstr *MI) {
861097a140dSpatrick if (!MI->isBundle())
862097a140dSpatrick return MI;
86309467b48Spatrick
864*d415bd75Srobert for (const auto &BMI : make_range(getBundleStart(MI->getIterator()),
865097a140dSpatrick getBundleEnd(MI->getIterator())))
866097a140dSpatrick if (BMI.isCandidateForCallSiteEntry())
867097a140dSpatrick return &BMI;
86809467b48Spatrick
869097a140dSpatrick llvm_unreachable("Unexpected bundle without a call site candidate");
87009467b48Spatrick }
87109467b48Spatrick
eraseCallSiteInfo(const MachineInstr * MI)87209467b48Spatrick void MachineFunction::eraseCallSiteInfo(const MachineInstr *MI) {
873097a140dSpatrick assert(MI->shouldUpdateCallSiteInfo() &&
874097a140dSpatrick "Call site info refers only to call (MI) candidates or "
875097a140dSpatrick "candidates inside bundles");
876097a140dSpatrick
877097a140dSpatrick const MachineInstr *CallMI = getCallInstr(MI);
878097a140dSpatrick CallSiteInfoMap::iterator CSIt = getCallSiteInfo(CallMI);
87909467b48Spatrick if (CSIt == CallSitesInfo.end())
88009467b48Spatrick return;
88109467b48Spatrick CallSitesInfo.erase(CSIt);
88209467b48Spatrick }
88309467b48Spatrick
copyCallSiteInfo(const MachineInstr * Old,const MachineInstr * New)88409467b48Spatrick void MachineFunction::copyCallSiteInfo(const MachineInstr *Old,
88509467b48Spatrick const MachineInstr *New) {
886097a140dSpatrick assert(Old->shouldUpdateCallSiteInfo() &&
887097a140dSpatrick "Call site info refers only to call (MI) candidates or "
888097a140dSpatrick "candidates inside bundles");
88909467b48Spatrick
890097a140dSpatrick if (!New->isCandidateForCallSiteEntry())
891097a140dSpatrick return eraseCallSiteInfo(Old);
892097a140dSpatrick
893097a140dSpatrick const MachineInstr *OldCallMI = getCallInstr(Old);
894097a140dSpatrick CallSiteInfoMap::iterator CSIt = getCallSiteInfo(OldCallMI);
89509467b48Spatrick if (CSIt == CallSitesInfo.end())
89609467b48Spatrick return;
89709467b48Spatrick
89809467b48Spatrick CallSiteInfo CSInfo = CSIt->second;
89909467b48Spatrick CallSitesInfo[New] = CSInfo;
90009467b48Spatrick }
90109467b48Spatrick
moveCallSiteInfo(const MachineInstr * Old,const MachineInstr * New)902097a140dSpatrick void MachineFunction::moveCallSiteInfo(const MachineInstr *Old,
903097a140dSpatrick const MachineInstr *New) {
904097a140dSpatrick assert(Old->shouldUpdateCallSiteInfo() &&
905097a140dSpatrick "Call site info refers only to call (MI) candidates or "
906097a140dSpatrick "candidates inside bundles");
907097a140dSpatrick
908097a140dSpatrick if (!New->isCandidateForCallSiteEntry())
909097a140dSpatrick return eraseCallSiteInfo(Old);
910097a140dSpatrick
911097a140dSpatrick const MachineInstr *OldCallMI = getCallInstr(Old);
912097a140dSpatrick CallSiteInfoMap::iterator CSIt = getCallSiteInfo(OldCallMI);
913097a140dSpatrick if (CSIt == CallSitesInfo.end())
914097a140dSpatrick return;
915097a140dSpatrick
916097a140dSpatrick CallSiteInfo CSInfo = std::move(CSIt->second);
917097a140dSpatrick CallSitesInfo.erase(CSIt);
918097a140dSpatrick CallSitesInfo[New] = CSInfo;
919097a140dSpatrick }
920097a140dSpatrick
setDebugInstrNumberingCount(unsigned Num)92173471bf0Spatrick void MachineFunction::setDebugInstrNumberingCount(unsigned Num) {
92273471bf0Spatrick DebugInstrNumberingCount = Num;
92373471bf0Spatrick }
92473471bf0Spatrick
makeDebugValueSubstitution(DebugInstrOperandPair A,DebugInstrOperandPair B,unsigned Subreg)92573471bf0Spatrick void MachineFunction::makeDebugValueSubstitution(DebugInstrOperandPair A,
92673471bf0Spatrick DebugInstrOperandPair B,
92773471bf0Spatrick unsigned Subreg) {
92873471bf0Spatrick // Catch any accidental self-loops.
92973471bf0Spatrick assert(A.first != B.first);
930*d415bd75Srobert // Don't allow any substitutions _from_ the memory operand number.
931*d415bd75Srobert assert(A.second != DebugOperandMemNumber);
932*d415bd75Srobert
93373471bf0Spatrick DebugValueSubstitutions.push_back({A, B, Subreg});
93473471bf0Spatrick }
93573471bf0Spatrick
substituteDebugValuesForInst(const MachineInstr & Old,MachineInstr & New,unsigned MaxOperand)93673471bf0Spatrick void MachineFunction::substituteDebugValuesForInst(const MachineInstr &Old,
93773471bf0Spatrick MachineInstr &New,
93873471bf0Spatrick unsigned MaxOperand) {
93973471bf0Spatrick // If the Old instruction wasn't tracked at all, there is no work to do.
94073471bf0Spatrick unsigned OldInstrNum = Old.peekDebugInstrNum();
94173471bf0Spatrick if (!OldInstrNum)
94273471bf0Spatrick return;
94373471bf0Spatrick
94473471bf0Spatrick // Iterate over all operands looking for defs to create substitutions for.
94573471bf0Spatrick // Avoid creating new instr numbers unless we create a new substitution.
94673471bf0Spatrick // While this has no functional effect, it risks confusing someone reading
94773471bf0Spatrick // MIR output.
94873471bf0Spatrick // Examine all the operands, or the first N specified by the caller.
94973471bf0Spatrick MaxOperand = std::min(MaxOperand, Old.getNumOperands());
95073471bf0Spatrick for (unsigned int I = 0; I < MaxOperand; ++I) {
95173471bf0Spatrick const auto &OldMO = Old.getOperand(I);
95273471bf0Spatrick auto &NewMO = New.getOperand(I);
95373471bf0Spatrick (void)NewMO;
95473471bf0Spatrick
95573471bf0Spatrick if (!OldMO.isReg() || !OldMO.isDef())
95673471bf0Spatrick continue;
95773471bf0Spatrick assert(NewMO.isDef());
95873471bf0Spatrick
95973471bf0Spatrick unsigned NewInstrNum = New.getDebugInstrNum();
96073471bf0Spatrick makeDebugValueSubstitution(std::make_pair(OldInstrNum, I),
96173471bf0Spatrick std::make_pair(NewInstrNum, I));
96273471bf0Spatrick }
96373471bf0Spatrick }
96473471bf0Spatrick
salvageCopySSA(MachineInstr & MI,DenseMap<Register,DebugInstrOperandPair> & DbgPHICache)965*d415bd75Srobert auto MachineFunction::salvageCopySSA(
966*d415bd75Srobert MachineInstr &MI, DenseMap<Register, DebugInstrOperandPair> &DbgPHICache)
967*d415bd75Srobert -> DebugInstrOperandPair {
968*d415bd75Srobert const TargetInstrInfo &TII = *getSubtarget().getInstrInfo();
969*d415bd75Srobert
970*d415bd75Srobert // Check whether this copy-like instruction has already been salvaged into
971*d415bd75Srobert // an operand pair.
972*d415bd75Srobert Register Dest;
973*d415bd75Srobert if (auto CopyDstSrc = TII.isCopyInstr(MI)) {
974*d415bd75Srobert Dest = CopyDstSrc->Destination->getReg();
975*d415bd75Srobert } else {
976*d415bd75Srobert assert(MI.isSubregToReg());
977*d415bd75Srobert Dest = MI.getOperand(0).getReg();
978*d415bd75Srobert }
979*d415bd75Srobert
980*d415bd75Srobert auto CacheIt = DbgPHICache.find(Dest);
981*d415bd75Srobert if (CacheIt != DbgPHICache.end())
982*d415bd75Srobert return CacheIt->second;
983*d415bd75Srobert
984*d415bd75Srobert // Calculate the instruction number to use, or install a DBG_PHI.
985*d415bd75Srobert auto OperandPair = salvageCopySSAImpl(MI);
986*d415bd75Srobert DbgPHICache.insert({Dest, OperandPair});
987*d415bd75Srobert return OperandPair;
988*d415bd75Srobert }
989*d415bd75Srobert
salvageCopySSAImpl(MachineInstr & MI)990*d415bd75Srobert auto MachineFunction::salvageCopySSAImpl(MachineInstr &MI)
99173471bf0Spatrick -> DebugInstrOperandPair {
99273471bf0Spatrick MachineRegisterInfo &MRI = getRegInfo();
99373471bf0Spatrick const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
99473471bf0Spatrick const TargetInstrInfo &TII = *getSubtarget().getInstrInfo();
99573471bf0Spatrick
99673471bf0Spatrick // Chase the value read by a copy-like instruction back to the instruction
99773471bf0Spatrick // that ultimately _defines_ that value. This may pass:
99873471bf0Spatrick // * Through multiple intermediate copies, including subregister moves /
99973471bf0Spatrick // copies,
100073471bf0Spatrick // * Copies from physical registers that must then be traced back to the
100173471bf0Spatrick // defining instruction,
100273471bf0Spatrick // * Or, physical registers may be live-in to (only) the entry block, which
100373471bf0Spatrick // requires a DBG_PHI to be created.
100473471bf0Spatrick // We can pursue this problem in that order: trace back through copies,
100573471bf0Spatrick // optionally through a physical register, to a defining instruction. We
100673471bf0Spatrick // should never move from physreg to vreg. As we're still in SSA form, no need
100773471bf0Spatrick // to worry about partial definitions of registers.
100873471bf0Spatrick
100973471bf0Spatrick // Helper lambda to interpret a copy-like instruction. Takes instruction,
101073471bf0Spatrick // returns the register read and any subregister identifying which part is
101173471bf0Spatrick // read.
101273471bf0Spatrick auto GetRegAndSubreg =
101373471bf0Spatrick [&](const MachineInstr &Cpy) -> std::pair<Register, unsigned> {
101473471bf0Spatrick Register NewReg, OldReg;
101573471bf0Spatrick unsigned SubReg;
101673471bf0Spatrick if (Cpy.isCopy()) {
101773471bf0Spatrick OldReg = Cpy.getOperand(0).getReg();
101873471bf0Spatrick NewReg = Cpy.getOperand(1).getReg();
101973471bf0Spatrick SubReg = Cpy.getOperand(1).getSubReg();
102073471bf0Spatrick } else if (Cpy.isSubregToReg()) {
102173471bf0Spatrick OldReg = Cpy.getOperand(0).getReg();
102273471bf0Spatrick NewReg = Cpy.getOperand(2).getReg();
102373471bf0Spatrick SubReg = Cpy.getOperand(3).getImm();
102473471bf0Spatrick } else {
102573471bf0Spatrick auto CopyDetails = *TII.isCopyInstr(Cpy);
102673471bf0Spatrick const MachineOperand &Src = *CopyDetails.Source;
102773471bf0Spatrick const MachineOperand &Dest = *CopyDetails.Destination;
102873471bf0Spatrick OldReg = Dest.getReg();
102973471bf0Spatrick NewReg = Src.getReg();
103073471bf0Spatrick SubReg = Src.getSubReg();
103173471bf0Spatrick }
103273471bf0Spatrick
103373471bf0Spatrick return {NewReg, SubReg};
103473471bf0Spatrick };
103573471bf0Spatrick
103673471bf0Spatrick // First seek either the defining instruction, or a copy from a physreg.
103773471bf0Spatrick // During search, the current state is the current copy instruction, and which
103873471bf0Spatrick // register we've read. Accumulate qualifying subregisters into SubregsSeen;
103973471bf0Spatrick // deal with those later.
104073471bf0Spatrick auto State = GetRegAndSubreg(MI);
104173471bf0Spatrick auto CurInst = MI.getIterator();
104273471bf0Spatrick SmallVector<unsigned, 4> SubregsSeen;
104373471bf0Spatrick while (true) {
104473471bf0Spatrick // If we've found a copy from a physreg, first portion of search is over.
104573471bf0Spatrick if (!State.first.isVirtual())
104673471bf0Spatrick break;
104773471bf0Spatrick
104873471bf0Spatrick // Record any subregister qualifier.
104973471bf0Spatrick if (State.second)
105073471bf0Spatrick SubregsSeen.push_back(State.second);
105173471bf0Spatrick
105273471bf0Spatrick assert(MRI.hasOneDef(State.first));
105373471bf0Spatrick MachineInstr &Inst = *MRI.def_begin(State.first)->getParent();
105473471bf0Spatrick CurInst = Inst.getIterator();
105573471bf0Spatrick
105673471bf0Spatrick // Any non-copy instruction is the defining instruction we're seeking.
105773471bf0Spatrick if (!Inst.isCopyLike() && !TII.isCopyInstr(Inst))
105873471bf0Spatrick break;
105973471bf0Spatrick State = GetRegAndSubreg(Inst);
106073471bf0Spatrick };
106173471bf0Spatrick
106273471bf0Spatrick // Helper lambda to apply additional subregister substitutions to a known
106373471bf0Spatrick // instruction/operand pair. Adds new (fake) substitutions so that we can
106473471bf0Spatrick // record the subregister. FIXME: this isn't very space efficient if multiple
106573471bf0Spatrick // values are tracked back through the same copies; cache something later.
106673471bf0Spatrick auto ApplySubregisters =
106773471bf0Spatrick [&](DebugInstrOperandPair P) -> DebugInstrOperandPair {
106873471bf0Spatrick for (unsigned Subreg : reverse(SubregsSeen)) {
106973471bf0Spatrick // Fetch a new instruction number, not attached to an actual instruction.
107073471bf0Spatrick unsigned NewInstrNumber = getNewDebugInstrNum();
107173471bf0Spatrick // Add a substitution from the "new" number to the known one, with a
107273471bf0Spatrick // qualifying subreg.
107373471bf0Spatrick makeDebugValueSubstitution({NewInstrNumber, 0}, P, Subreg);
107473471bf0Spatrick // Return the new number; to find the underlying value, consumers need to
107573471bf0Spatrick // deal with the qualifying subreg.
107673471bf0Spatrick P = {NewInstrNumber, 0};
107773471bf0Spatrick }
107873471bf0Spatrick return P;
107973471bf0Spatrick };
108073471bf0Spatrick
108173471bf0Spatrick // If we managed to find the defining instruction after COPYs, return an
108273471bf0Spatrick // instruction / operand pair after adding subregister qualifiers.
108373471bf0Spatrick if (State.first.isVirtual()) {
108473471bf0Spatrick // Virtual register def -- we can just look up where this happens.
108573471bf0Spatrick MachineInstr *Inst = MRI.def_begin(State.first)->getParent();
108673471bf0Spatrick for (auto &MO : Inst->operands()) {
108773471bf0Spatrick if (!MO.isReg() || !MO.isDef() || MO.getReg() != State.first)
108873471bf0Spatrick continue;
108973471bf0Spatrick return ApplySubregisters(
109073471bf0Spatrick {Inst->getDebugInstrNum(), Inst->getOperandNo(&MO)});
109173471bf0Spatrick }
109273471bf0Spatrick
109373471bf0Spatrick llvm_unreachable("Vreg def with no corresponding operand?");
109473471bf0Spatrick }
109573471bf0Spatrick
109673471bf0Spatrick // Our search ended in a copy from a physreg: walk back up the function
109773471bf0Spatrick // looking for whatever defines the physreg.
109873471bf0Spatrick assert(CurInst->isCopyLike() || TII.isCopyInstr(*CurInst));
109973471bf0Spatrick State = GetRegAndSubreg(*CurInst);
110073471bf0Spatrick Register RegToSeek = State.first;
110173471bf0Spatrick
110273471bf0Spatrick auto RMII = CurInst->getReverseIterator();
110373471bf0Spatrick auto PrevInstrs = make_range(RMII, CurInst->getParent()->instr_rend());
110473471bf0Spatrick for (auto &ToExamine : PrevInstrs) {
110573471bf0Spatrick for (auto &MO : ToExamine.operands()) {
110673471bf0Spatrick // Test for operand that defines something aliasing RegToSeek.
110773471bf0Spatrick if (!MO.isReg() || !MO.isDef() ||
110873471bf0Spatrick !TRI.regsOverlap(RegToSeek, MO.getReg()))
110973471bf0Spatrick continue;
111073471bf0Spatrick
111173471bf0Spatrick return ApplySubregisters(
111273471bf0Spatrick {ToExamine.getDebugInstrNum(), ToExamine.getOperandNo(&MO)});
111373471bf0Spatrick }
111473471bf0Spatrick }
111573471bf0Spatrick
111673471bf0Spatrick MachineBasicBlock &InsertBB = *CurInst->getParent();
111773471bf0Spatrick
111873471bf0Spatrick // We reached the start of the block before finding a defining instruction.
1119*d415bd75Srobert // There are numerous scenarios where this can happen:
1120*d415bd75Srobert // * Constant physical registers,
1121*d415bd75Srobert // * Several intrinsics that allow LLVM-IR to read arbitary registers,
1122*d415bd75Srobert // * Arguments in the entry block,
1123*d415bd75Srobert // * Exception handling landing pads.
1124*d415bd75Srobert // Validating all of them is too difficult, so just insert a DBG_PHI reading
1125*d415bd75Srobert // the variable value at this position, rather than checking it makes sense.
112673471bf0Spatrick
112773471bf0Spatrick // Create DBG_PHI for specified physreg.
112873471bf0Spatrick auto Builder = BuildMI(InsertBB, InsertBB.getFirstNonPHI(), DebugLoc(),
112973471bf0Spatrick TII.get(TargetOpcode::DBG_PHI));
1130*d415bd75Srobert Builder.addReg(State.first);
113173471bf0Spatrick unsigned NewNum = getNewDebugInstrNum();
113273471bf0Spatrick Builder.addImm(NewNum);
113373471bf0Spatrick return ApplySubregisters({NewNum, 0u});
113473471bf0Spatrick }
113573471bf0Spatrick
finalizeDebugInstrRefs()113673471bf0Spatrick void MachineFunction::finalizeDebugInstrRefs() {
113773471bf0Spatrick auto *TII = getSubtarget().getInstrInfo();
113873471bf0Spatrick
1139*d415bd75Srobert auto MakeUndefDbgValue = [&](MachineInstr &MI) {
1140*d415bd75Srobert const MCInstrDesc &RefII = TII->get(TargetOpcode::DBG_VALUE_LIST);
114173471bf0Spatrick MI.setDesc(RefII);
1142*d415bd75Srobert MI.setDebugValueUndef();
114373471bf0Spatrick };
114473471bf0Spatrick
1145*d415bd75Srobert DenseMap<Register, DebugInstrOperandPair> ArgDbgPHIs;
114673471bf0Spatrick for (auto &MBB : *this) {
114773471bf0Spatrick for (auto &MI : MBB) {
1148*d415bd75Srobert if (!MI.isDebugRef())
114973471bf0Spatrick continue;
115073471bf0Spatrick
1151*d415bd75Srobert bool IsValidRef = true;
1152*d415bd75Srobert
1153*d415bd75Srobert for (MachineOperand &MO : MI.debug_operands()) {
1154*d415bd75Srobert if (!MO.isReg())
1155*d415bd75Srobert continue;
1156*d415bd75Srobert
1157*d415bd75Srobert Register Reg = MO.getReg();
115873471bf0Spatrick
115973471bf0Spatrick // Some vregs can be deleted as redundant in the meantime. Mark those
1160*d415bd75Srobert // as DBG_VALUE $noreg. Additionally, some normal instructions are
1161*d415bd75Srobert // quickly deleted, leaving dangling references to vregs with no def.
1162*d415bd75Srobert if (Reg == 0 || !RegInfo->hasOneDef(Reg)) {
1163*d415bd75Srobert IsValidRef = false;
1164*d415bd75Srobert break;
116573471bf0Spatrick }
116673471bf0Spatrick
116773471bf0Spatrick assert(Reg.isVirtual());
116873471bf0Spatrick MachineInstr &DefMI = *RegInfo->def_instr_begin(Reg);
116973471bf0Spatrick
117073471bf0Spatrick // If we've found a copy-like instruction, follow it back to the
117173471bf0Spatrick // instruction that defines the source value, see salvageCopySSA docs
117273471bf0Spatrick // for why this is important.
117373471bf0Spatrick if (DefMI.isCopyLike() || TII->isCopyInstr(DefMI)) {
1174*d415bd75Srobert auto Result = salvageCopySSA(DefMI, ArgDbgPHIs);
1175*d415bd75Srobert MO.ChangeToDbgInstrRef(Result.first, Result.second);
117673471bf0Spatrick } else {
117773471bf0Spatrick // Otherwise, identify the operand number that the VReg refers to.
117873471bf0Spatrick unsigned OperandIdx = 0;
1179*d415bd75Srobert for (const auto &DefMO : DefMI.operands()) {
1180*d415bd75Srobert if (DefMO.isReg() && DefMO.isDef() && DefMO.getReg() == Reg)
118173471bf0Spatrick break;
118273471bf0Spatrick ++OperandIdx;
118373471bf0Spatrick }
118473471bf0Spatrick assert(OperandIdx < DefMI.getNumOperands());
118573471bf0Spatrick
118673471bf0Spatrick // Morph this instr ref to point at the given instruction and operand.
118773471bf0Spatrick unsigned ID = DefMI.getDebugInstrNum();
1188*d415bd75Srobert MO.ChangeToDbgInstrRef(ID, OperandIdx);
1189*d415bd75Srobert }
1190*d415bd75Srobert }
1191*d415bd75Srobert
1192*d415bd75Srobert if (!IsValidRef)
1193*d415bd75Srobert MakeUndefDbgValue(MI);
119473471bf0Spatrick }
119573471bf0Spatrick }
119673471bf0Spatrick }
1197*d415bd75Srobert
shouldUseDebugInstrRef() const1198*d415bd75Srobert bool MachineFunction::shouldUseDebugInstrRef() const {
1199*d415bd75Srobert // Disable instr-ref at -O0: it's very slow (in compile time). We can still
1200*d415bd75Srobert // have optimized code inlined into this unoptimized code, however with
1201*d415bd75Srobert // fewer and less aggressive optimizations happening, coverage and accuracy
1202*d415bd75Srobert // should not suffer.
1203*d415bd75Srobert if (getTarget().getOptLevel() == CodeGenOpt::None)
1204*d415bd75Srobert return false;
1205*d415bd75Srobert
1206*d415bd75Srobert // Don't use instr-ref if this function is marked optnone.
1207*d415bd75Srobert if (F.hasFnAttribute(Attribute::OptimizeNone))
1208*d415bd75Srobert return false;
1209*d415bd75Srobert
1210*d415bd75Srobert if (llvm::debuginfoShouldUseDebugInstrRef(getTarget().getTargetTriple()))
1211*d415bd75Srobert return true;
1212*d415bd75Srobert
1213*d415bd75Srobert return false;
121473471bf0Spatrick }
121573471bf0Spatrick
useDebugInstrRef() const1216*d415bd75Srobert bool MachineFunction::useDebugInstrRef() const {
1217*d415bd75Srobert return UseDebugInstrRef;
1218*d415bd75Srobert }
1219*d415bd75Srobert
setUseDebugInstrRef(bool Use)1220*d415bd75Srobert void MachineFunction::setUseDebugInstrRef(bool Use) {
1221*d415bd75Srobert UseDebugInstrRef = Use;
1222*d415bd75Srobert }
1223*d415bd75Srobert
1224*d415bd75Srobert // Use one million as a high / reserved number.
1225*d415bd75Srobert const unsigned MachineFunction::DebugOperandMemNumber = 1000000;
1226*d415bd75Srobert
122709467b48Spatrick /// \}
122809467b48Spatrick
122909467b48Spatrick //===----------------------------------------------------------------------===//
123009467b48Spatrick // MachineJumpTableInfo implementation
123109467b48Spatrick //===----------------------------------------------------------------------===//
123209467b48Spatrick
123309467b48Spatrick /// Return the size of each entry in the jump table.
getEntrySize(const DataLayout & TD) const123409467b48Spatrick unsigned MachineJumpTableInfo::getEntrySize(const DataLayout &TD) const {
123509467b48Spatrick // The size of a jump table entry is 4 bytes unless the entry is just the
123609467b48Spatrick // address of a block, in which case it is the pointer size.
123709467b48Spatrick switch (getEntryKind()) {
123809467b48Spatrick case MachineJumpTableInfo::EK_BlockAddress:
123909467b48Spatrick return TD.getPointerSize();
124009467b48Spatrick case MachineJumpTableInfo::EK_GPRel64BlockAddress:
124109467b48Spatrick return 8;
124209467b48Spatrick case MachineJumpTableInfo::EK_GPRel32BlockAddress:
124309467b48Spatrick case MachineJumpTableInfo::EK_LabelDifference32:
124409467b48Spatrick case MachineJumpTableInfo::EK_Custom32:
124509467b48Spatrick return 4;
124609467b48Spatrick case MachineJumpTableInfo::EK_Inline:
124709467b48Spatrick return 0;
124809467b48Spatrick }
124909467b48Spatrick llvm_unreachable("Unknown jump table encoding!");
125009467b48Spatrick }
125109467b48Spatrick
125209467b48Spatrick /// Return the alignment of each entry in the jump table.
getEntryAlignment(const DataLayout & TD) const125309467b48Spatrick unsigned MachineJumpTableInfo::getEntryAlignment(const DataLayout &TD) const {
125409467b48Spatrick // The alignment of a jump table entry is the alignment of int32 unless the
125509467b48Spatrick // entry is just the address of a block, in which case it is the pointer
125609467b48Spatrick // alignment.
125709467b48Spatrick switch (getEntryKind()) {
125809467b48Spatrick case MachineJumpTableInfo::EK_BlockAddress:
125909467b48Spatrick return TD.getPointerABIAlignment(0).value();
126009467b48Spatrick case MachineJumpTableInfo::EK_GPRel64BlockAddress:
126109467b48Spatrick return TD.getABIIntegerTypeAlignment(64).value();
126209467b48Spatrick case MachineJumpTableInfo::EK_GPRel32BlockAddress:
126309467b48Spatrick case MachineJumpTableInfo::EK_LabelDifference32:
126409467b48Spatrick case MachineJumpTableInfo::EK_Custom32:
126509467b48Spatrick return TD.getABIIntegerTypeAlignment(32).value();
126609467b48Spatrick case MachineJumpTableInfo::EK_Inline:
126709467b48Spatrick return 1;
126809467b48Spatrick }
126909467b48Spatrick llvm_unreachable("Unknown jump table encoding!");
127009467b48Spatrick }
127109467b48Spatrick
127209467b48Spatrick /// Create a new jump table entry in the jump table info.
createJumpTableIndex(const std::vector<MachineBasicBlock * > & DestBBs)127309467b48Spatrick unsigned MachineJumpTableInfo::createJumpTableIndex(
127409467b48Spatrick const std::vector<MachineBasicBlock*> &DestBBs) {
127509467b48Spatrick assert(!DestBBs.empty() && "Cannot create an empty jump table!");
127609467b48Spatrick JumpTables.push_back(MachineJumpTableEntry(DestBBs));
127709467b48Spatrick return JumpTables.size()-1;
127809467b48Spatrick }
127909467b48Spatrick
128009467b48Spatrick /// If Old is the target of any jump tables, update the jump tables to branch
128109467b48Spatrick /// to New instead.
ReplaceMBBInJumpTables(MachineBasicBlock * Old,MachineBasicBlock * New)128209467b48Spatrick bool MachineJumpTableInfo::ReplaceMBBInJumpTables(MachineBasicBlock *Old,
128309467b48Spatrick MachineBasicBlock *New) {
128409467b48Spatrick assert(Old != New && "Not making a change?");
128509467b48Spatrick bool MadeChange = false;
128609467b48Spatrick for (size_t i = 0, e = JumpTables.size(); i != e; ++i)
128709467b48Spatrick ReplaceMBBInJumpTable(i, Old, New);
128809467b48Spatrick return MadeChange;
128909467b48Spatrick }
129009467b48Spatrick
129173471bf0Spatrick /// If MBB is present in any jump tables, remove it.
RemoveMBBFromJumpTables(MachineBasicBlock * MBB)129273471bf0Spatrick bool MachineJumpTableInfo::RemoveMBBFromJumpTables(MachineBasicBlock *MBB) {
129373471bf0Spatrick bool MadeChange = false;
129473471bf0Spatrick for (MachineJumpTableEntry &JTE : JumpTables) {
129573471bf0Spatrick auto removeBeginItr = std::remove(JTE.MBBs.begin(), JTE.MBBs.end(), MBB);
129673471bf0Spatrick MadeChange |= (removeBeginItr != JTE.MBBs.end());
129773471bf0Spatrick JTE.MBBs.erase(removeBeginItr, JTE.MBBs.end());
129873471bf0Spatrick }
129973471bf0Spatrick return MadeChange;
130073471bf0Spatrick }
130173471bf0Spatrick
130209467b48Spatrick /// If Old is a target of the jump tables, update the jump table to branch to
130309467b48Spatrick /// New instead.
ReplaceMBBInJumpTable(unsigned Idx,MachineBasicBlock * Old,MachineBasicBlock * New)130409467b48Spatrick bool MachineJumpTableInfo::ReplaceMBBInJumpTable(unsigned Idx,
130509467b48Spatrick MachineBasicBlock *Old,
130609467b48Spatrick MachineBasicBlock *New) {
130709467b48Spatrick assert(Old != New && "Not making a change?");
130809467b48Spatrick bool MadeChange = false;
130909467b48Spatrick MachineJumpTableEntry &JTE = JumpTables[Idx];
1310*d415bd75Srobert for (MachineBasicBlock *&MBB : JTE.MBBs)
1311*d415bd75Srobert if (MBB == Old) {
1312*d415bd75Srobert MBB = New;
131309467b48Spatrick MadeChange = true;
131409467b48Spatrick }
131509467b48Spatrick return MadeChange;
131609467b48Spatrick }
131709467b48Spatrick
print(raw_ostream & OS) const131809467b48Spatrick void MachineJumpTableInfo::print(raw_ostream &OS) const {
131909467b48Spatrick if (JumpTables.empty()) return;
132009467b48Spatrick
132109467b48Spatrick OS << "Jump Tables:\n";
132209467b48Spatrick
132309467b48Spatrick for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
132409467b48Spatrick OS << printJumpTableEntryReference(i) << ':';
1325*d415bd75Srobert for (const MachineBasicBlock *MBB : JumpTables[i].MBBs)
1326*d415bd75Srobert OS << ' ' << printMBBReference(*MBB);
132709467b48Spatrick if (i != e)
132809467b48Spatrick OS << '\n';
132909467b48Spatrick }
133009467b48Spatrick
133109467b48Spatrick OS << '\n';
133209467b48Spatrick }
133309467b48Spatrick
133409467b48Spatrick #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
dump() const133509467b48Spatrick LLVM_DUMP_METHOD void MachineJumpTableInfo::dump() const { print(dbgs()); }
133609467b48Spatrick #endif
133709467b48Spatrick
printJumpTableEntryReference(unsigned Idx)133809467b48Spatrick Printable llvm::printJumpTableEntryReference(unsigned Idx) {
133909467b48Spatrick return Printable([Idx](raw_ostream &OS) { OS << "%jump-table." << Idx; });
134009467b48Spatrick }
134109467b48Spatrick
134209467b48Spatrick //===----------------------------------------------------------------------===//
134309467b48Spatrick // MachineConstantPool implementation
134409467b48Spatrick //===----------------------------------------------------------------------===//
134509467b48Spatrick
anchor()134609467b48Spatrick void MachineConstantPoolValue::anchor() {}
134709467b48Spatrick
getSizeInBytes(const DataLayout & DL) const134873471bf0Spatrick unsigned MachineConstantPoolValue::getSizeInBytes(const DataLayout &DL) const {
134973471bf0Spatrick return DL.getTypeAllocSize(Ty);
135073471bf0Spatrick }
135173471bf0Spatrick
getSizeInBytes(const DataLayout & DL) const135273471bf0Spatrick unsigned MachineConstantPoolEntry::getSizeInBytes(const DataLayout &DL) const {
135309467b48Spatrick if (isMachineConstantPoolEntry())
135473471bf0Spatrick return Val.MachineCPVal->getSizeInBytes(DL);
135573471bf0Spatrick return DL.getTypeAllocSize(Val.ConstVal->getType());
135609467b48Spatrick }
135709467b48Spatrick
needsRelocation() const135809467b48Spatrick bool MachineConstantPoolEntry::needsRelocation() const {
135909467b48Spatrick if (isMachineConstantPoolEntry())
136009467b48Spatrick return true;
136173471bf0Spatrick return Val.ConstVal->needsDynamicRelocation();
136209467b48Spatrick }
136309467b48Spatrick
136409467b48Spatrick SectionKind
getSectionKind(const DataLayout * DL) const136509467b48Spatrick MachineConstantPoolEntry::getSectionKind(const DataLayout *DL) const {
136609467b48Spatrick if (needsRelocation())
136709467b48Spatrick return SectionKind::getReadOnlyWithRel();
136873471bf0Spatrick switch (getSizeInBytes(*DL)) {
136909467b48Spatrick case 4:
137009467b48Spatrick return SectionKind::getMergeableConst4();
137109467b48Spatrick case 8:
137209467b48Spatrick return SectionKind::getMergeableConst8();
137309467b48Spatrick case 16:
137409467b48Spatrick return SectionKind::getMergeableConst16();
137509467b48Spatrick case 32:
137609467b48Spatrick return SectionKind::getMergeableConst32();
137709467b48Spatrick default:
137809467b48Spatrick return SectionKind::getReadOnly();
137909467b48Spatrick }
138009467b48Spatrick }
138109467b48Spatrick
~MachineConstantPool()138209467b48Spatrick MachineConstantPool::~MachineConstantPool() {
138309467b48Spatrick // A constant may be a member of both Constants and MachineCPVsSharingEntries,
138409467b48Spatrick // so keep track of which we've deleted to avoid double deletions.
138509467b48Spatrick DenseSet<MachineConstantPoolValue*> Deleted;
1386*d415bd75Srobert for (const MachineConstantPoolEntry &C : Constants)
1387*d415bd75Srobert if (C.isMachineConstantPoolEntry()) {
1388*d415bd75Srobert Deleted.insert(C.Val.MachineCPVal);
1389*d415bd75Srobert delete C.Val.MachineCPVal;
139009467b48Spatrick }
139173471bf0Spatrick for (MachineConstantPoolValue *CPV : MachineCPVsSharingEntries) {
139273471bf0Spatrick if (Deleted.count(CPV) == 0)
139373471bf0Spatrick delete CPV;
139409467b48Spatrick }
139509467b48Spatrick }
139609467b48Spatrick
139709467b48Spatrick /// Test whether the given two constants can be allocated the same constant pool
139809467b48Spatrick /// entry.
CanShareConstantPoolEntry(const Constant * A,const Constant * B,const DataLayout & DL)139909467b48Spatrick static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B,
140009467b48Spatrick const DataLayout &DL) {
140109467b48Spatrick // Handle the trivial case quickly.
140209467b48Spatrick if (A == B) return true;
140309467b48Spatrick
140409467b48Spatrick // If they have the same type but weren't the same constant, quickly
140509467b48Spatrick // reject them.
140609467b48Spatrick if (A->getType() == B->getType()) return false;
140709467b48Spatrick
140809467b48Spatrick // We can't handle structs or arrays.
140909467b48Spatrick if (isa<StructType>(A->getType()) || isa<ArrayType>(A->getType()) ||
141009467b48Spatrick isa<StructType>(B->getType()) || isa<ArrayType>(B->getType()))
141109467b48Spatrick return false;
141209467b48Spatrick
141309467b48Spatrick // For now, only support constants with the same size.
141409467b48Spatrick uint64_t StoreSize = DL.getTypeStoreSize(A->getType());
141509467b48Spatrick if (StoreSize != DL.getTypeStoreSize(B->getType()) || StoreSize > 128)
141609467b48Spatrick return false;
141709467b48Spatrick
141809467b48Spatrick Type *IntTy = IntegerType::get(A->getContext(), StoreSize*8);
141909467b48Spatrick
142009467b48Spatrick // Try constant folding a bitcast of both instructions to an integer. If we
142109467b48Spatrick // get two identical ConstantInt's, then we are good to share them. We use
142209467b48Spatrick // the constant folding APIs to do this so that we get the benefit of
142309467b48Spatrick // DataLayout.
142409467b48Spatrick if (isa<PointerType>(A->getType()))
142509467b48Spatrick A = ConstantFoldCastOperand(Instruction::PtrToInt,
142609467b48Spatrick const_cast<Constant *>(A), IntTy, DL);
142709467b48Spatrick else if (A->getType() != IntTy)
142809467b48Spatrick A = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(A),
142909467b48Spatrick IntTy, DL);
143009467b48Spatrick if (isa<PointerType>(B->getType()))
143109467b48Spatrick B = ConstantFoldCastOperand(Instruction::PtrToInt,
143209467b48Spatrick const_cast<Constant *>(B), IntTy, DL);
143309467b48Spatrick else if (B->getType() != IntTy)
143409467b48Spatrick B = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(B),
143509467b48Spatrick IntTy, DL);
143609467b48Spatrick
143709467b48Spatrick return A == B;
143809467b48Spatrick }
143909467b48Spatrick
144009467b48Spatrick /// Create a new entry in the constant pool or return an existing one.
144109467b48Spatrick /// User must specify the log2 of the minimum required alignment for the object.
getConstantPoolIndex(const Constant * C,Align Alignment)144209467b48Spatrick unsigned MachineConstantPool::getConstantPoolIndex(const Constant *C,
1443097a140dSpatrick Align Alignment) {
144409467b48Spatrick if (Alignment > PoolAlignment) PoolAlignment = Alignment;
144509467b48Spatrick
144609467b48Spatrick // Check to see if we already have this constant.
144709467b48Spatrick //
144809467b48Spatrick // FIXME, this could be made much more efficient for large constant pools.
144909467b48Spatrick for (unsigned i = 0, e = Constants.size(); i != e; ++i)
145009467b48Spatrick if (!Constants[i].isMachineConstantPoolEntry() &&
145109467b48Spatrick CanShareConstantPoolEntry(Constants[i].Val.ConstVal, C, DL)) {
1452097a140dSpatrick if (Constants[i].getAlign() < Alignment)
145309467b48Spatrick Constants[i].Alignment = Alignment;
145409467b48Spatrick return i;
145509467b48Spatrick }
145609467b48Spatrick
145709467b48Spatrick Constants.push_back(MachineConstantPoolEntry(C, Alignment));
145809467b48Spatrick return Constants.size()-1;
145909467b48Spatrick }
146009467b48Spatrick
getConstantPoolIndex(MachineConstantPoolValue * V,Align Alignment)146109467b48Spatrick unsigned MachineConstantPool::getConstantPoolIndex(MachineConstantPoolValue *V,
1462097a140dSpatrick Align Alignment) {
146309467b48Spatrick if (Alignment > PoolAlignment) PoolAlignment = Alignment;
146409467b48Spatrick
146509467b48Spatrick // Check to see if we already have this constant.
146609467b48Spatrick //
146709467b48Spatrick // FIXME, this could be made much more efficient for large constant pools.
146809467b48Spatrick int Idx = V->getExistingMachineCPValue(this, Alignment);
146909467b48Spatrick if (Idx != -1) {
147009467b48Spatrick MachineCPVsSharingEntries.insert(V);
147109467b48Spatrick return (unsigned)Idx;
147209467b48Spatrick }
147309467b48Spatrick
147409467b48Spatrick Constants.push_back(MachineConstantPoolEntry(V, Alignment));
147509467b48Spatrick return Constants.size()-1;
147609467b48Spatrick }
147709467b48Spatrick
print(raw_ostream & OS) const147809467b48Spatrick void MachineConstantPool::print(raw_ostream &OS) const {
147909467b48Spatrick if (Constants.empty()) return;
148009467b48Spatrick
148109467b48Spatrick OS << "Constant Pool:\n";
148209467b48Spatrick for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
148309467b48Spatrick OS << " cp#" << i << ": ";
148409467b48Spatrick if (Constants[i].isMachineConstantPoolEntry())
148509467b48Spatrick Constants[i].Val.MachineCPVal->print(OS);
148609467b48Spatrick else
148709467b48Spatrick Constants[i].Val.ConstVal->printAsOperand(OS, /*PrintType=*/false);
1488097a140dSpatrick OS << ", align=" << Constants[i].getAlign().value();
148909467b48Spatrick OS << "\n";
149009467b48Spatrick }
149109467b48Spatrick }
149209467b48Spatrick
149309467b48Spatrick #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
dump() const149409467b48Spatrick LLVM_DUMP_METHOD void MachineConstantPool::dump() const { print(dbgs()); }
149509467b48Spatrick #endif
1496