Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 1 | //===- MachineFunction.cpp ------------------------------------------------===// |
Alkis Evlogimenos | b920999 | 2004-09-05 18:41:35 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | ca6d719 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Alkis Evlogimenos | b920999 | 2004-09-05 18:41:35 +0000 | [diff] [blame] | 6 | // |
John Criswell | 287baed | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | b920999 | 2004-09-05 18:41:35 +0000 | [diff] [blame] | 8 | // |
Chris Lattner | 45ffeff | 2002-10-28 01:16:38 +0000 | [diff] [blame] | 9 | // Collect native machine code information for a function. This allows |
| 10 | // target-specific information about the generated code to be stored with each |
| 11 | // function. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
Chris Lattner | 3eb005a | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 14 | |
David Greene | 284ccd0 | 2009-08-19 22:16:11 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/MachineFunction.h" |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/BitVector.h" |
| 17 | #include "llvm/ADT/DenseMap.h" |
| 18 | #include "llvm/ADT/DenseSet.h" |
Chandler Carruth | 345b827 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/STLExtras.h" |
| 20 | #include "llvm/ADT/SmallString.h" |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallVector.h" |
| 22 | #include "llvm/ADT/StringRef.h" |
| 23 | #include "llvm/ADT/Twine.h" |
Chandler Carruth | 345b827 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 24 | #include "llvm/Analysis/ConstantFolding.h" |
Han Shen | c5e8527 | 2023-06-28 22:18:53 -0700 | [diff] [blame] | 25 | #include "llvm/Analysis/ProfileSummaryInfo.h" |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/MachineBasicBlock.h" |
Chris Lattner | 00016e8 | 2012-01-27 01:47:28 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/MachineConstantPool.h" |
Chris Lattner | 6534a42 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 29 | #include "llvm/CodeGen/MachineInstr.h" |
Nate Begeman | 83e5f08 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineJumpTableInfo.h" |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineMemOperand.h" |
Chris Lattner | 0673780 | 2010-04-05 05:49:50 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Chris Lattner | 6534a42 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Alex Lorenz | 00e26a1 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/PseudoSourceValue.h" |
David Blaikie | cee844d | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/TargetFrameLowering.h" |
Sriraman Tallam | ccf30a7 | 2020-03-16 15:56:02 -0700 | [diff] [blame] | 36 | #include "llvm/CodeGen/TargetInstrInfo.h" |
David Blaikie | cee844d | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 37 | #include "llvm/CodeGen/TargetLowering.h" |
| 38 | #include "llvm/CodeGen/TargetRegisterInfo.h" |
| 39 | #include "llvm/CodeGen/TargetSubtargetInfo.h" |
Heejin Ahn | 06f97e3 | 2018-06-19 00:26:39 +0000 | [diff] [blame] | 40 | #include "llvm/CodeGen/WasmEHFuncInfo.h" |
Reid Kleckner | 832a539 | 2015-11-17 21:10:25 +0000 | [diff] [blame] | 41 | #include "llvm/CodeGen/WinEHFuncInfo.h" |
Nico Weber | e887240 | 2018-04-30 14:59:11 +0000 | [diff] [blame] | 42 | #include "llvm/Config/llvm-config.h" |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 43 | #include "llvm/IR/Attributes.h" |
| 44 | #include "llvm/IR/BasicBlock.h" |
| 45 | #include "llvm/IR/Constant.h" |
Chandler Carruth | 1d569b6 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 46 | #include "llvm/IR/DataLayout.h" |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 47 | #include "llvm/IR/DerivedTypes.h" |
Stefan Gränitz | 51a75df | 2023-01-24 12:29:53 +0100 | [diff] [blame] | 48 | #include "llvm/IR/EHPersonalities.h" |
Chandler Carruth | 1d569b6 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 49 | #include "llvm/IR/Function.h" |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 50 | #include "llvm/IR/GlobalValue.h" |
| 51 | #include "llvm/IR/Instruction.h" |
| 52 | #include "llvm/IR/Instructions.h" |
| 53 | #include "llvm/IR/Metadata.h" |
Mehdi Amini | c0a24f6 | 2015-07-07 18:20:57 +0000 | [diff] [blame] | 54 | #include "llvm/IR/Module.h" |
Duncan P. N. Exon Smith | 318caae | 2015-06-26 22:04:20 +0000 | [diff] [blame] | 55 | #include "llvm/IR/ModuleSlotTracker.h" |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 56 | #include "llvm/IR/Value.h" |
Chris Lattner | 80a6849 | 2010-01-26 05:58:28 +0000 | [diff] [blame] | 57 | #include "llvm/MC/MCContext.h" |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 58 | #include "llvm/MC/MCSymbol.h" |
| 59 | #include "llvm/MC/SectionKind.h" |
| 60 | #include "llvm/Support/Casting.h" |
| 61 | #include "llvm/Support/CommandLine.h" |
| 62 | #include "llvm/Support/Compiler.h" |
| 63 | #include "llvm/Support/DOTGraphTraits.h" |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 64 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | 744980f | 2006-10-03 20:19:23 +0000 | [diff] [blame] | 65 | #include "llvm/Support/GraphWriter.h" |
Chris Lattner | abed347 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 66 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | 345b827 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 67 | #include "llvm/Target/TargetMachine.h" |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 68 | #include <algorithm> |
| 69 | #include <cassert> |
| 70 | #include <cstddef> |
| 71 | #include <cstdint> |
| 72 | #include <iterator> |
| 73 | #include <string> |
Sriraman Tallam | ccf30a7 | 2020-03-16 15:56:02 -0700 | [diff] [blame] | 74 | #include <type_traits> |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 75 | #include <utility> |
| 76 | #include <vector> |
| 77 | |
Jeremy Morse | 5550704 | 2022-01-12 12:35:36 +0000 | [diff] [blame] | 78 | #include "LiveDebugValues/LiveDebugValues.h" |
| 79 | |
Chris Lattner | 46c2a2a | 2003-12-20 09:17:07 +0000 | [diff] [blame] | 80 | using namespace llvm; |
Chris Lattner | 3eb005a | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 81 | |
Chandler Carruth | 636c071 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 82 | #define DEBUG_TYPE "codegen" |
| 83 | |
Guillaume Chatelet | 0f68677 | 2019-09-05 10:00:22 +0000 | [diff] [blame] | 84 | static cl::opt<unsigned> AlignAllFunctions( |
| 85 | "align-all-functions", |
| 86 | cl::desc("Force the alignment of all functions in log2 format (e.g. 4 " |
| 87 | "means align on 16B boundaries)."), |
| 88 | cl::init(0), cl::Hidden); |
Chad Rosier | 7fc299b | 2015-12-29 18:18:07 +0000 | [diff] [blame] | 89 | |
Matthias Braun | 88257e9 | 2016-08-19 22:31:45 +0000 | [diff] [blame] | 90 | static const char *getPropertyName(MachineFunctionProperties::Property Prop) { |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 91 | using P = MachineFunctionProperties::Property; |
| 92 | |
Jack Andersen | e6f03ce | 2021-12-05 14:55:20 -0500 | [diff] [blame] | 93 | // clang-format off |
Matthias Braun | 88257e9 | 2016-08-19 22:31:45 +0000 | [diff] [blame] | 94 | switch(Prop) { |
Quentin Colombet | e468a57 | 2016-08-26 23:49:01 +0000 | [diff] [blame] | 95 | case P::FailedISel: return "FailedISel"; |
Matthias Braun | 88257e9 | 2016-08-19 22:31:45 +0000 | [diff] [blame] | 96 | case P::IsSSA: return "IsSSA"; |
| 97 | case P::Legalized: return "Legalized"; |
Matthias Braun | b93e0fa | 2016-08-23 21:19:49 +0000 | [diff] [blame] | 98 | case P::NoPHIs: return "NoPHIs"; |
Matthias Braun | 60d4720 | 2016-08-25 01:27:13 +0000 | [diff] [blame] | 99 | case P::NoVRegs: return "NoVRegs"; |
Matthias Braun | 88257e9 | 2016-08-19 22:31:45 +0000 | [diff] [blame] | 100 | case P::RegBankSelected: return "RegBankSelected"; |
| 101 | case P::Selected: return "Selected"; |
| 102 | case P::TracksLiveness: return "TracksLiveness"; |
Kang Zhang | d13b1c6 | 2020-06-09 07:39:42 +0000 | [diff] [blame] | 103 | case P::TiedOpsRewritten: return "TiedOpsRewritten"; |
Jay Foad | 82d0463 | 2021-10-15 11:26:48 +0100 | [diff] [blame] | 104 | case P::FailsVerification: return "FailsVerification"; |
Jack Andersen | e6f03ce | 2021-12-05 14:55:20 -0500 | [diff] [blame] | 105 | case P::TracksDebugUserValues: return "TracksDebugUserValues"; |
Derek Schuff | 690a2c8 | 2016-03-29 20:28:20 +0000 | [diff] [blame] | 106 | } |
Jack Andersen | e6f03ce | 2021-12-05 14:55:20 -0500 | [diff] [blame] | 107 | // clang-format on |
Matthias Braun | d6aa4ae | 2016-08-19 23:03:28 +0000 | [diff] [blame] | 108 | llvm_unreachable("Invalid machine function property"); |
Matthias Braun | 88257e9 | 2016-08-19 22:31:45 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Paul Kirth | 4524b53 | 2022-04-19 16:34:23 +0000 | [diff] [blame] | 111 | void setUnsafeStackSize(const Function &F, MachineFrameInfo &FrameInfo) { |
| 112 | if (!F.hasFnAttribute(Attribute::SafeStack)) |
| 113 | return; |
| 114 | |
| 115 | auto *Existing = |
| 116 | dyn_cast_or_null<MDTuple>(F.getMetadata(LLVMContext::MD_annotation)); |
| 117 | |
| 118 | if (!Existing || Existing->getNumOperands() != 2) |
| 119 | return; |
| 120 | |
| 121 | auto *MetadataName = "unsafe-stack-size"; |
| 122 | if (auto &N = Existing->getOperand(0)) { |
Zain Jaffal | 749bae6 | 2023-05-09 17:15:13 +0300 | [diff] [blame] | 123 | if (N.equalsStr(MetadataName)) { |
Paul Kirth | 4524b53 | 2022-04-19 16:34:23 +0000 | [diff] [blame] | 124 | if (auto &Op = Existing->getOperand(1)) { |
| 125 | auto Val = mdconst::extract<ConstantInt>(Op)->getZExtValue(); |
| 126 | FrameInfo.setUnsafeStackSize(Val); |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
Aditya Nandakumar | fb36700 | 2018-09-20 23:01:56 +0000 | [diff] [blame] | 132 | // Pin the vtable to this file. |
| 133 | void MachineFunction::Delegate::anchor() {} |
| 134 | |
Matthias Braun | 88257e9 | 2016-08-19 22:31:45 +0000 | [diff] [blame] | 135 | void MachineFunctionProperties::print(raw_ostream &OS) const { |
| 136 | const char *Separator = ""; |
| 137 | for (BitVector::size_type I = 0; I < Properties.size(); ++I) { |
| 138 | if (!Properties[I]) |
| 139 | continue; |
| 140 | OS << Separator << getPropertyName(static_cast<Property>(I)); |
| 141 | Separator = ", "; |
| 142 | } |
Derek Schuff | 690a2c8 | 2016-03-29 20:28:20 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Chris Lattner | 88f25f2 | 2010-01-26 04:35:26 +0000 | [diff] [blame] | 145 | //===----------------------------------------------------------------------===// |
Chris Lattner | 49eb81b | 2002-10-28 01:12:41 +0000 | [diff] [blame] | 146 | // MachineFunction implementation |
Chris Lattner | 88f25f2 | 2010-01-26 04:35:26 +0000 | [diff] [blame] | 147 | //===----------------------------------------------------------------------===// |
Chris Lattner | 38fa729 | 2005-01-29 18:41:25 +0000 | [diff] [blame] | 148 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 149 | // Out-of-line virtual method. |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 150 | MachineFunctionInfo::~MachineFunctionInfo() = default; |
Chris Lattner | cdbc2a21 | 2009-09-15 22:44:26 +0000 | [diff] [blame] | 151 | |
Duncan P. N. Exon Smith | 183446f | 2016-08-30 18:40:47 +0000 | [diff] [blame] | 152 | void ilist_alloc_traits<MachineBasicBlock>::deleteNode(MachineBasicBlock *MBB) { |
Mircea Trofin | e4cd868 | 2021-12-08 17:36:37 -0800 | [diff] [blame] | 153 | MBB->getParent()->deleteMachineBasicBlock(MBB); |
Tanya Lattner | 4158d13 | 2004-05-24 06:11:51 +0000 | [diff] [blame] | 154 | } |
Chris Lattner | 49eb81b | 2002-10-28 01:12:41 +0000 | [diff] [blame] | 155 | |
Guillaume Chatelet | 0193045 | 2022-06-17 15:13:10 +0000 | [diff] [blame] | 156 | static inline Align getFnStackAlignment(const TargetSubtargetInfo *STI, |
Matthias Braun | dc82338 | 2017-12-15 22:22:46 +0000 | [diff] [blame] | 157 | const Function &F) { |
Arthur Eubanks | 577fcdd | 2021-08-18 10:43:17 -0700 | [diff] [blame] | 158 | if (auto MA = F.getFnStackAlign()) |
Guillaume Chatelet | 0193045 | 2022-06-17 15:13:10 +0000 | [diff] [blame] | 159 | return *MA; |
| 160 | return STI->getFrameLowering()->getStackAlign(); |
Charles Davis | 3ff19ce | 2016-04-09 23:34:42 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Daniel Sanders | 5d27a23 | 2020-04-03 15:55:15 -0700 | [diff] [blame] | 163 | MachineFunction::MachineFunction(Function &F, const LLVMTargetMachine &Target, |
Matthias Braun | dc82338 | 2017-12-15 22:22:46 +0000 | [diff] [blame] | 164 | const TargetSubtargetInfo &STI, |
Rafael Espindola | ca4806b | 2014-10-14 18:53:16 +0000 | [diff] [blame] | 165 | unsigned FunctionNum, MachineModuleInfo &mmi) |
Matthias Braun | dc82338 | 2017-12-15 22:22:46 +0000 | [diff] [blame] | 166 | : F(F), Target(Target), STI(&STI), Ctx(mmi.getContext()), MMI(mmi) { |
Quentin Colombet | 9f61c38 | 2016-08-26 22:32:53 +0000 | [diff] [blame] | 167 | FunctionNumber = FunctionNum; |
| 168 | init(); |
| 169 | } |
| 170 | |
Aditya Nandakumar | d7b5c2e | 2019-01-16 00:40:37 +0000 | [diff] [blame] | 171 | void MachineFunction::handleInsertion(MachineInstr &MI) { |
Aditya Nandakumar | fb36700 | 2018-09-20 23:01:56 +0000 | [diff] [blame] | 172 | if (TheDelegate) |
| 173 | TheDelegate->MF_HandleInsertion(MI); |
| 174 | } |
| 175 | |
Aditya Nandakumar | d7b5c2e | 2019-01-16 00:40:37 +0000 | [diff] [blame] | 176 | void MachineFunction::handleRemoval(MachineInstr &MI) { |
Aditya Nandakumar | fb36700 | 2018-09-20 23:01:56 +0000 | [diff] [blame] | 177 | if (TheDelegate) |
| 178 | TheDelegate->MF_HandleRemoval(MI); |
| 179 | } |
| 180 | |
Quentin Colombet | 9f61c38 | 2016-08-26 22:32:53 +0000 | [diff] [blame] | 181 | void MachineFunction::init() { |
Derek Schuff | ab6e545 | 2016-04-11 23:32:13 +0000 | [diff] [blame] | 182 | // Assume the function starts in SSA form with correct liveness. |
Derek Schuff | 02e9062 | 2016-04-04 18:03:29 +0000 | [diff] [blame] | 183 | Properties.set(MachineFunctionProperties::Property::IsSSA); |
Derek Schuff | ab6e545 | 2016-04-11 23:32:13 +0000 | [diff] [blame] | 184 | Properties.set(MachineFunctionProperties::Property::TracksLiveness); |
Eric Christopher | f69bb7a | 2014-10-08 07:51:41 +0000 | [diff] [blame] | 185 | if (STI->getRegisterInfo()) |
Eric Christopher | 8eb35a9 | 2014-08-12 08:00:56 +0000 | [diff] [blame] | 186 | RegInfo = new (Allocator) MachineRegisterInfo(this); |
Matthijs Kooijman | 7167be4 | 2008-10-13 12:37:16 +0000 | [diff] [blame] | 187 | else |
Craig Topper | 64a7a81 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 188 | RegInfo = nullptr; |
Bill Wendling | e6d6f3e | 2013-06-17 20:41:25 +0000 | [diff] [blame] | 189 | |
Craig Topper | 64a7a81 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 190 | MFInfo = nullptr; |
Matt Arsenault | c951faf | 2020-06-18 09:00:16 -0400 | [diff] [blame] | 191 | |
Reid Kleckner | 9b464c7a | 2016-04-11 17:54:03 +0000 | [diff] [blame] | 192 | // We can realign the stack if the target supports it and the user hasn't |
| 193 | // explicitly asked us not to. |
| 194 | bool CanRealignSP = STI->getFrameLowering()->isStackRealignable() && |
Matthias Braun | dc82338 | 2017-12-15 22:22:46 +0000 | [diff] [blame] | 195 | !F.hasFnAttribute("no-realign-stack"); |
Reid Kleckner | 9b464c7a | 2016-04-11 17:54:03 +0000 | [diff] [blame] | 196 | FrameInfo = new (Allocator) MachineFrameInfo( |
Matthias Braun | dc82338 | 2017-12-15 22:22:46 +0000 | [diff] [blame] | 197 | getFnStackAlignment(STI, F), /*StackRealignable=*/CanRealignSP, |
Rui Ueyama | 08343a2 | 2019-07-16 04:46:31 +0000 | [diff] [blame] | 198 | /*ForcedRealign=*/CanRealignSP && |
Matthias Braun | dc82338 | 2017-12-15 22:22:46 +0000 | [diff] [blame] | 199 | F.hasFnAttribute(Attribute::StackAlignment)); |
Bill Wendling | e6d6f3e | 2013-06-17 20:41:25 +0000 | [diff] [blame] | 200 | |
Paul Kirth | 4524b53 | 2022-04-19 16:34:23 +0000 | [diff] [blame] | 201 | setUnsafeStackSize(F, *FrameInfo); |
| 202 | |
Matthias Braun | dc82338 | 2017-12-15 22:22:46 +0000 | [diff] [blame] | 203 | if (F.hasFnAttribute(Attribute::StackAlignment)) |
Guillaume Chatelet | 76848e6 | 2020-03-18 17:04:10 +0100 | [diff] [blame] | 204 | FrameInfo->ensureMaxAlignment(*F.getFnStackAlign()); |
Bill Wendling | e6d6f3e | 2013-06-17 20:41:25 +0000 | [diff] [blame] | 205 | |
Mehdi Amini | c0a24f6 | 2015-07-07 18:20:57 +0000 | [diff] [blame] | 206 | ConstantPool = new (Allocator) MachineConstantPool(getDataLayout()); |
Guillaume Chatelet | d619012 | 2019-09-11 11:16:48 +0000 | [diff] [blame] | 207 | Alignment = STI->getTargetLowering()->getMinFunctionAlignment(); |
Bill Wendling | e6d6f3e | 2013-06-17 20:41:25 +0000 | [diff] [blame] | 208 | |
Matthias Braun | dc82338 | 2017-12-15 22:22:46 +0000 | [diff] [blame] | 209 | // FIXME: Shouldn't use pref alignment if explicit alignment is set on F. |
Evandro Menezes | e09b2ad | 2019-04-04 22:40:06 +0000 | [diff] [blame] | 210 | // FIXME: Use Function::hasOptSize(). |
Matthias Braun | dc82338 | 2017-12-15 22:22:46 +0000 | [diff] [blame] | 211 | if (!F.hasFnAttribute(Attribute::OptimizeForSize)) |
Guillaume Chatelet | d619012 | 2019-09-11 11:16:48 +0000 | [diff] [blame] | 212 | Alignment = std::max(Alignment, |
| 213 | STI->getTargetLowering()->getPrefFunctionAlignment()); |
Bill Wendling | e6d6f3e | 2013-06-17 20:41:25 +0000 | [diff] [blame] | 214 | |
Fangrui Song | 32938e0 | 2023-06-30 09:13:19 -0700 | [diff] [blame] | 215 | // -fsanitize=function and -fsanitize=kcfi instrument indirect function calls |
| 216 | // to load a type hash before the function label. Ensure functions are aligned |
| 217 | // by a least 4 to avoid unaligned access, which is especially important for |
| 218 | // -mno-unaligned-access. |
| 219 | if (F.hasMetadata(LLVMContext::MD_func_sanitize) || |
| 220 | F.getMetadata(LLVMContext::MD_kcfi_type)) |
| 221 | Alignment = std::max(Alignment, Align(4)); |
| 222 | |
Chad Rosier | 7fc299b | 2015-12-29 18:18:07 +0000 | [diff] [blame] | 223 | if (AlignAllFunctions) |
Guillaume Chatelet | 549dc0a | 2019-09-27 12:54:21 +0000 | [diff] [blame] | 224 | Alignment = Align(1ULL << AlignAllFunctions); |
Chad Rosier | 7fc299b | 2015-12-29 18:18:07 +0000 | [diff] [blame] | 225 | |
Craig Topper | 64a7a81 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 226 | JumpTableInfo = nullptr; |
Tobias Grosser | 318a7dc | 2015-08-17 10:58:03 +0000 | [diff] [blame] | 227 | |
Reid Kleckner | 832a539 | 2015-11-17 21:10:25 +0000 | [diff] [blame] | 228 | if (isFuncletEHPersonality(classifyEHPersonality( |
Matthias Braun | dc82338 | 2017-12-15 22:22:46 +0000 | [diff] [blame] | 229 | F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr))) { |
Reid Kleckner | 832a539 | 2015-11-17 21:10:25 +0000 | [diff] [blame] | 230 | WinEHInfo = new (Allocator) WinEHFuncInfo(); |
| 231 | } |
| 232 | |
Heejin Ahn | 06f97e3 | 2018-06-19 00:26:39 +0000 | [diff] [blame] | 233 | if (isScopedEHPersonality(classifyEHPersonality( |
| 234 | F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr))) { |
| 235 | WasmEHInfo = new (Allocator) WasmEHFuncInfo(); |
| 236 | } |
| 237 | |
Quentin Colombet | 9f61c38 | 2016-08-26 22:32:53 +0000 | [diff] [blame] | 238 | assert(Target.isCompatibleDataLayout(getDataLayout()) && |
Tobias Grosser | 318a7dc | 2015-08-17 10:58:03 +0000 | [diff] [blame] | 239 | "Can't create a MachineFunction using a Module with a " |
| 240 | "Target-incompatible DataLayout attached\n"); |
| 241 | |
Matt Arsenault | 1d05d40 | 2022-04-26 20:35:01 -0400 | [diff] [blame] | 242 | PSVManager = std::make_unique<PseudoSourceValueManager>(getTarget()); |
Chris Lattner | a55f646 | 2002-12-25 05:03:22 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Matt Arsenault | c951faf | 2020-06-18 09:00:16 -0400 | [diff] [blame] | 245 | void MachineFunction::initTargetMachineFunctionInfo( |
| 246 | const TargetSubtargetInfo &STI) { |
| 247 | assert(!MFInfo && "MachineFunctionInfo already set"); |
| 248 | MFInfo = Target.createMachineFunctionInfo(Allocator, F, &STI); |
| 249 | } |
| 250 | |
Alkis Evlogimenos | b920999 | 2004-09-05 18:41:35 +0000 | [diff] [blame] | 251 | MachineFunction::~MachineFunction() { |
Quentin Colombet | 9f61c38 | 2016-08-26 22:32:53 +0000 | [diff] [blame] | 252 | clear(); |
| 253 | } |
| 254 | |
| 255 | void MachineFunction::clear() { |
| 256 | Properties.reset(); |
Jakob Stoklund Olesen | 70d9c47 | 2013-01-05 05:05:51 +0000 | [diff] [blame] | 257 | // Don't call destructors on MachineInstr and MachineOperand. All of their |
| 258 | // memory comes from the BumpPtrAllocator which is about to be purged. |
| 259 | // |
| 260 | // Do call MachineBasicBlock destructors, it contains std::vectors. |
| 261 | for (iterator I = begin(), E = end(); I != E; I = BasicBlocks.erase(I)) |
| 262 | I->Insts.clearAndLeakNodesUnsafely(); |
Roman Tereshin | 5971445 | 2018-04-30 18:58:57 +0000 | [diff] [blame] | 263 | MBBNumbering.clear(); |
Jakob Stoklund Olesen | 70d9c47 | 2013-01-05 05:05:51 +0000 | [diff] [blame] | 264 | |
Dan Gohman | 1f4347b | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 265 | InstructionRecycler.clear(Allocator); |
Jakob Stoklund Olesen | 1828d3f | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 266 | OperandRecycler.clear(Allocator); |
Dan Gohman | 1f4347b | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 267 | BasicBlockRecycler.clear(Allocator); |
Reid Kleckner | f9e7734 | 2017-09-05 20:14:58 +0000 | [diff] [blame] | 268 | CodeViewAnnotations.clear(); |
Tim Northover | 4ead40c | 2017-03-09 21:12:06 +0000 | [diff] [blame] | 269 | VariableDbgInfos.clear(); |
Bill Wendling | 027af70 | 2009-06-25 00:32:48 +0000 | [diff] [blame] | 270 | if (RegInfo) { |
| 271 | RegInfo->~MachineRegisterInfo(); |
| 272 | Allocator.Deallocate(RegInfo); |
| 273 | } |
Dan Gohman | 1f4347b | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 274 | if (MFInfo) { |
Bill Wendling | 027af70 | 2009-06-25 00:32:48 +0000 | [diff] [blame] | 275 | MFInfo->~MachineFunctionInfo(); |
| 276 | Allocator.Deallocate(MFInfo); |
Dan Gohman | 1f4347b | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 277 | } |
Chad Rosier | be02a0a | 2012-06-19 23:37:57 +0000 | [diff] [blame] | 278 | |
| 279 | FrameInfo->~MachineFrameInfo(); |
| 280 | Allocator.Deallocate(FrameInfo); |
| 281 | |
| 282 | ConstantPool->~MachineConstantPool(); |
| 283 | Allocator.Deallocate(ConstantPool); |
| 284 | |
Chris Lattner | 5b5cc06 | 2010-01-25 23:26:13 +0000 | [diff] [blame] | 285 | if (JumpTableInfo) { |
| 286 | JumpTableInfo->~MachineJumpTableInfo(); |
| 287 | Allocator.Deallocate(JumpTableInfo); |
| 288 | } |
Reid Kleckner | 832a539 | 2015-11-17 21:10:25 +0000 | [diff] [blame] | 289 | |
| 290 | if (WinEHInfo) { |
| 291 | WinEHInfo->~WinEHFuncInfo(); |
| 292 | Allocator.Deallocate(WinEHInfo); |
| 293 | } |
Heejin Ahn | ddc0e4b | 2018-09-28 20:54:04 +0000 | [diff] [blame] | 294 | |
| 295 | if (WasmEHInfo) { |
| 296 | WasmEHInfo->~WasmEHFuncInfo(); |
| 297 | Allocator.Deallocate(WasmEHInfo); |
| 298 | } |
Chris Lattner | a7f707c | 2002-10-30 00:48:05 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Mehdi Amini | c0a24f6 | 2015-07-07 18:20:57 +0000 | [diff] [blame] | 301 | const DataLayout &MachineFunction::getDataLayout() const { |
Matthias Braun | dc82338 | 2017-12-15 22:22:46 +0000 | [diff] [blame] | 302 | return F.getParent()->getDataLayout(); |
Mehdi Amini | c0a24f6 | 2015-07-07 18:20:57 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 305 | /// Get the JumpTableInfo for this function. |
| 306 | /// If it does not already exist, allocate one. |
Chris Lattner | 5b5cc06 | 2010-01-25 23:26:13 +0000 | [diff] [blame] | 307 | MachineJumpTableInfo *MachineFunction:: |
| 308 | getOrCreateJumpTableInfo(unsigned EntryKind) { |
| 309 | if (JumpTableInfo) return JumpTableInfo; |
Chad Rosier | be02a0a | 2012-06-19 23:37:57 +0000 | [diff] [blame] | 310 | |
Dan Gohman | 7874c61 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 311 | JumpTableInfo = new (Allocator) |
Chris Lattner | 5b5cc06 | 2010-01-25 23:26:13 +0000 | [diff] [blame] | 312 | MachineJumpTableInfo((MachineJumpTableInfo::JTEntryKind)EntryKind); |
| 313 | return JumpTableInfo; |
| 314 | } |
Chris Lattner | 743066a | 2006-10-03 19:18:57 +0000 | [diff] [blame] | 315 | |
Matt Arsenault | 6d0718c | 2019-10-29 16:16:05 -0700 | [diff] [blame] | 316 | DenormalMode MachineFunction::getDenormalMode(const fltSemantics &FPType) const { |
Matt Arsenault | 47daf8f | 2020-09-17 17:50:42 -0400 | [diff] [blame] | 317 | return F.getDenormalMode(FPType); |
Matt Arsenault | 6d0718c | 2019-10-29 16:16:05 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Reid Kleckner | 1406803 | 2014-04-10 22:58:43 +0000 | [diff] [blame] | 320 | /// Should we be emitting segmented stack stuff for the function |
Quentin Colombet | cd8d5eb | 2016-01-19 22:31:12 +0000 | [diff] [blame] | 321 | bool MachineFunction::shouldSplitStack() const { |
Matthias Braun | 5863fee | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 322 | return getFunction().hasFnAttribute("split-stack"); |
Reid Kleckner | 1406803 | 2014-04-10 22:58:43 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Fangrui Song | d0c2e95 | 2022-08-07 00:26:33 +0000 | [diff] [blame] | 325 | [[nodiscard]] unsigned |
Eric Christopher | 2df8714 | 2019-04-12 06:31:59 +0000 | [diff] [blame] | 326 | MachineFunction::addFrameInst(const MCCFIInstruction &Inst) { |
| 327 | FrameInstructions.push_back(Inst); |
| 328 | return FrameInstructions.size() - 1; |
| 329 | } |
| 330 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 331 | /// This discards all of the MachineBasicBlock numbers and recomputes them. |
| 332 | /// This guarantees that the MBB numbers are sequential, dense, and match the |
| 333 | /// ordering of the blocks within the function. If a specific MachineBasicBlock |
| 334 | /// is specified, only that block and those after it are renumbered. |
Chris Lattner | 743066a | 2006-10-03 19:18:57 +0000 | [diff] [blame] | 335 | void MachineFunction::RenumberBlocks(MachineBasicBlock *MBB) { |
| 336 | if (empty()) { MBBNumbering.clear(); return; } |
| 337 | MachineFunction::iterator MBBI, E = end(); |
Craig Topper | 64a7a81 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 338 | if (MBB == nullptr) |
Chris Lattner | 743066a | 2006-10-03 19:18:57 +0000 | [diff] [blame] | 339 | MBBI = begin(); |
| 340 | else |
Duncan P. N. Exon Smith | 4188761 | 2015-10-09 19:40:45 +0000 | [diff] [blame] | 341 | MBBI = MBB->getIterator(); |
Chad Rosier | be02a0a | 2012-06-19 23:37:57 +0000 | [diff] [blame] | 342 | |
Chris Lattner | 743066a | 2006-10-03 19:18:57 +0000 | [diff] [blame] | 343 | // Figure out the block number this should have. |
| 344 | unsigned BlockNo = 0; |
Chris Lattner | 744980f | 2006-10-03 20:19:23 +0000 | [diff] [blame] | 345 | if (MBBI != begin()) |
Benjamin Kramer | 52ceb71 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 346 | BlockNo = std::prev(MBBI)->getNumber() + 1; |
Chad Rosier | be02a0a | 2012-06-19 23:37:57 +0000 | [diff] [blame] | 347 | |
Chris Lattner | 743066a | 2006-10-03 19:18:57 +0000 | [diff] [blame] | 348 | for (; MBBI != E; ++MBBI, ++BlockNo) { |
| 349 | if (MBBI->getNumber() != (int)BlockNo) { |
| 350 | // Remove use of the old number. |
| 351 | if (MBBI->getNumber() != -1) { |
| 352 | assert(MBBNumbering[MBBI->getNumber()] == &*MBBI && |
| 353 | "MBB number mismatch!"); |
Craig Topper | 64a7a81 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 354 | MBBNumbering[MBBI->getNumber()] = nullptr; |
Chris Lattner | 743066a | 2006-10-03 19:18:57 +0000 | [diff] [blame] | 355 | } |
Chad Rosier | be02a0a | 2012-06-19 23:37:57 +0000 | [diff] [blame] | 356 | |
Chris Lattner | 743066a | 2006-10-03 19:18:57 +0000 | [diff] [blame] | 357 | // If BlockNo is already taken, set that block's number to -1. |
| 358 | if (MBBNumbering[BlockNo]) |
| 359 | MBBNumbering[BlockNo]->setNumber(-1); |
| 360 | |
Duncan P. N. Exon Smith | 4188761 | 2015-10-09 19:40:45 +0000 | [diff] [blame] | 361 | MBBNumbering[BlockNo] = &*MBBI; |
Chris Lattner | 743066a | 2006-10-03 19:18:57 +0000 | [diff] [blame] | 362 | MBBI->setNumber(BlockNo); |
| 363 | } |
Chad Rosier | be02a0a | 2012-06-19 23:37:57 +0000 | [diff] [blame] | 364 | } |
Chris Lattner | 743066a | 2006-10-03 19:18:57 +0000 | [diff] [blame] | 365 | |
| 366 | // Okay, all the blocks are renumbered. If we have compactified the block |
| 367 | // numbering, shrink MBBNumbering now. |
| 368 | assert(BlockNo <= MBBNumbering.size() && "Mismatch!"); |
| 369 | MBBNumbering.resize(BlockNo); |
| 370 | } |
| 371 | |
Rahman Lavaee | 9e2e75e | 2020-04-13 12:14:42 -0700 | [diff] [blame] | 372 | /// This method iterates over the basic blocks and assigns their IsBeginSection |
| 373 | /// and IsEndSection fields. This must be called after MBB layout is finalized |
| 374 | /// and the SectionID's are assigned to MBBs. |
| 375 | void MachineFunction::assignBeginEndSections() { |
| 376 | front().setIsBeginSection(); |
| 377 | auto CurrentSectionID = front().getSectionID(); |
| 378 | for (auto MBBI = std::next(begin()), E = end(); MBBI != E; ++MBBI) { |
| 379 | if (MBBI->getSectionID() == CurrentSectionID) |
| 380 | continue; |
| 381 | MBBI->setIsBeginSection(); |
| 382 | std::prev(MBBI)->setIsEndSection(); |
| 383 | CurrentSectionID = MBBI->getSectionID(); |
| 384 | } |
| 385 | back().setIsEndSection(); |
| 386 | } |
| 387 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 388 | /// Allocate a new MachineInstr. Use this instead of `new MachineInstr'. |
Benjamin Kramer | f0389a8 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 389 | MachineInstr *MachineFunction::CreateMachineInstr(const MCInstrDesc &MCID, |
Mircea Trofin | 06b3f02 | 2021-12-06 17:33:13 -0800 | [diff] [blame] | 390 | DebugLoc DL, |
Fangrui Song | 5305455 | 2020-09-19 20:41:25 -0700 | [diff] [blame] | 391 | bool NoImplicit) { |
Dan Gohman | 1f4347b | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 392 | return new (InstructionRecycler.Allocate<MachineInstr>(Allocator)) |
Mircea Trofin | 06b3f02 | 2021-12-06 17:33:13 -0800 | [diff] [blame] | 393 | MachineInstr(*this, MCID, std::move(DL), NoImplicit); |
Dan Gohman | 1f4347b | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 394 | } |
Chris Lattner | 743066a | 2006-10-03 19:18:57 +0000 | [diff] [blame] | 395 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 396 | /// Create a new MachineInstr which is a copy of the 'Orig' instruction, |
| 397 | /// identical in all ways except the instruction has no parent, prev, or next. |
Dan Gohman | 1f4347b | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 398 | MachineInstr * |
| 399 | MachineFunction::CloneMachineInstr(const MachineInstr *Orig) { |
| 400 | return new (InstructionRecycler.Allocate<MachineInstr>(Allocator)) |
| 401 | MachineInstr(*this, *Orig); |
| 402 | } |
| 403 | |
Mircea Trofin | a77637a | 2021-12-08 21:12:54 -0800 | [diff] [blame] | 404 | MachineInstr &MachineFunction::cloneMachineInstrBundle( |
| 405 | MachineBasicBlock &MBB, MachineBasicBlock::iterator InsertBefore, |
| 406 | const MachineInstr &Orig) { |
Matthias Braun | 0908223 | 2017-08-22 23:56:30 +0000 | [diff] [blame] | 407 | MachineInstr *FirstClone = nullptr; |
| 408 | MachineBasicBlock::const_instr_iterator I = Orig.getIterator(); |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 409 | while (true) { |
Matthias Braun | 0908223 | 2017-08-22 23:56:30 +0000 | [diff] [blame] | 410 | MachineInstr *Cloned = CloneMachineInstr(&*I); |
| 411 | MBB.insert(InsertBefore, Cloned); |
| 412 | if (FirstClone == nullptr) { |
| 413 | FirstClone = Cloned; |
| 414 | } else { |
| 415 | Cloned->bundleWithPred(); |
| 416 | } |
| 417 | |
| 418 | if (!I->isBundledWithSucc()) |
| 419 | break; |
| 420 | ++I; |
| 421 | } |
Vedant Kumar | 6c71c58 | 2020-04-07 13:09:29 -0700 | [diff] [blame] | 422 | // Copy over call site info to the cloned instruction if needed. If Orig is in |
| 423 | // a bundle, copyCallSiteInfo takes care of finding the call instruction in |
| 424 | // the bundle. |
| 425 | if (Orig.shouldUpdateCallSiteInfo()) |
| 426 | copyCallSiteInfo(&Orig, FirstClone); |
Matthias Braun | 0908223 | 2017-08-22 23:56:30 +0000 | [diff] [blame] | 427 | return *FirstClone; |
| 428 | } |
| 429 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 430 | /// Delete the given MachineInstr. |
Dan Gohman | 1f4347b | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 431 | /// |
Jakob Stoklund Olesen | 70d9c47 | 2013-01-05 05:05:51 +0000 | [diff] [blame] | 432 | /// This function also serves as the MachineInstr destructor - the real |
| 433 | /// ~MachineInstr() destructor must be empty. |
Mircea Trofin | 8134d49 | 2021-12-08 20:35:33 -0800 | [diff] [blame] | 434 | void MachineFunction::deleteMachineInstr(MachineInstr *MI) { |
Djordje Todorovic | b4e1c25 | 2019-06-27 13:10:29 +0000 | [diff] [blame] | 435 | // Verify that a call site info is at valid state. This assertion should |
| 436 | // be triggered during the implementation of support for the |
| 437 | // call site info of a new architecture. If the assertion is triggered, |
| 438 | // back trace will tell where to insert a call to updateCallSiteInfo(). |
Kazu Hirata | 03cf956 | 2023-03-15 18:06:32 -0700 | [diff] [blame] | 439 | assert((!MI->isCandidateForCallSiteEntry() || !CallSitesInfo.contains(MI)) && |
Djordje Todorovic | b4e1c25 | 2019-06-27 13:10:29 +0000 | [diff] [blame] | 440 | "Call site info was not updated!"); |
Jakob Stoklund Olesen | 1828d3f | 2013-01-05 05:00:09 +0000 | [diff] [blame] | 441 | // Strip it for parts. The operand array and the MI object itself are |
| 442 | // independently recyclable. |
| 443 | if (MI->Operands) |
| 444 | deallocateOperandArray(MI->CapOperands, MI->Operands); |
Jakob Stoklund Olesen | 70d9c47 | 2013-01-05 05:05:51 +0000 | [diff] [blame] | 445 | // Don't call ~MachineInstr() which must be trivial anyway because |
| 446 | // ~MachineFunction drops whole lists of MachineInstrs wihout calling their |
| 447 | // destructors. |
Dan Gohman | 1f4347b | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 448 | InstructionRecycler.Deallocate(Allocator, MI); |
| 449 | } |
| 450 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 451 | /// Allocate a new MachineBasicBlock. Use this instead of |
| 452 | /// `new MachineBasicBlock'. |
Dan Gohman | 1f4347b | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 453 | MachineBasicBlock * |
| 454 | MachineFunction::CreateMachineBasicBlock(const BasicBlock *bb) { |
Rahman Lavaee | 050b8da | 2022-12-06 22:37:33 -0800 | [diff] [blame] | 455 | MachineBasicBlock *MBB = |
| 456 | new (BasicBlockRecycler.Allocate<MachineBasicBlock>(Allocator)) |
| 457 | MachineBasicBlock(*this, bb); |
| 458 | // Set BBID for `-basic-block=sections=labels` and |
| 459 | // `-basic-block-sections=list` to allow robust mapping of profiles to basic |
| 460 | // blocks. |
| 461 | if (Target.getBBSectionsType() == BasicBlockSection::Labels || |
| 462 | Target.getBBSectionsType() == BasicBlockSection::List) |
| 463 | MBB->setBBID(NextBBID++); |
| 464 | return MBB; |
Dan Gohman | 1f4347b | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 467 | /// Delete the given MachineBasicBlock. |
Mircea Trofin | e4cd868 | 2021-12-08 17:36:37 -0800 | [diff] [blame] | 468 | void MachineFunction::deleteMachineBasicBlock(MachineBasicBlock *MBB) { |
Dan Gohman | 1f4347b | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 469 | assert(MBB->getParent() == this && "MBB parent mismatch!"); |
Victor Huang | 347c461 | 2020-11-16 10:33:06 -0600 | [diff] [blame] | 470 | // Clean up any references to MBB in jump tables before deleting it. |
| 471 | if (JumpTableInfo) |
| 472 | JumpTableInfo->RemoveMBBFromJumpTables(MBB); |
Dan Gohman | 1f4347b | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 473 | MBB->~MachineBasicBlock(); |
| 474 | BasicBlockRecycler.Deallocate(Allocator, MBB); |
| 475 | } |
| 476 | |
Justin Lebar | f4c231a | 2016-07-15 18:26:59 +0000 | [diff] [blame] | 477 | MachineMemOperand *MachineFunction::getMachineMemOperand( |
| 478 | MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, |
Guillaume Chatelet | 8b16e93 | 2020-03-30 09:38:44 +0000 | [diff] [blame] | 479 | Align base_alignment, const AAMDNodes &AAInfo, const MDNode *Ranges, |
Konstantin Zhuravlyov | df2c53c | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 480 | SyncScope::ID SSID, AtomicOrdering Ordering, |
Konstantin Zhuravlyov | eef4c7a | 2016-10-15 22:01:18 +0000 | [diff] [blame] | 481 | AtomicOrdering FailureOrdering) { |
Justin Lebar | 4dd3ec9 | 2016-07-14 17:07:44 +0000 | [diff] [blame] | 482 | return new (Allocator) |
Konstantin Zhuravlyov | eef4c7a | 2016-10-15 22:01:18 +0000 | [diff] [blame] | 483 | MachineMemOperand(PtrInfo, f, s, base_alignment, AAInfo, Ranges, |
Konstantin Zhuravlyov | df2c53c | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 484 | SSID, Ordering, FailureOrdering); |
Dan Gohman | 4ba0275 | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 485 | } |
| 486 | |
David Sherwood | dd10b5f | 2020-07-14 13:50:21 +0100 | [diff] [blame] | 487 | MachineMemOperand *MachineFunction::getMachineMemOperand( |
Matt Arsenault | d08403b | 2021-05-19 22:06:14 -0400 | [diff] [blame] | 488 | MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, |
| 489 | Align base_alignment, const AAMDNodes &AAInfo, const MDNode *Ranges, |
| 490 | SyncScope::ID SSID, AtomicOrdering Ordering, |
| 491 | AtomicOrdering FailureOrdering) { |
| 492 | return new (Allocator) |
| 493 | MachineMemOperand(PtrInfo, f, MemTy, base_alignment, AAInfo, Ranges, SSID, |
| 494 | Ordering, FailureOrdering); |
| 495 | } |
| 496 | |
| 497 | MachineMemOperand *MachineFunction::getMachineMemOperand( |
Matt Arsenault | 6b91eca | 2021-06-08 17:10:51 -0400 | [diff] [blame] | 498 | const MachineMemOperand *MMO, const MachinePointerInfo &PtrInfo, uint64_t Size) { |
Eli Friedman | 4d7b2bb | 2021-06-21 16:34:02 -0700 | [diff] [blame] | 499 | return new (Allocator) |
| 500 | MachineMemOperand(PtrInfo, MMO->getFlags(), Size, MMO->getBaseAlign(), |
| 501 | AAMDNodes(), nullptr, MMO->getSyncScopeID(), |
| 502 | MMO->getSuccessOrdering(), MMO->getFailureOrdering()); |
David Sherwood | dd10b5f | 2020-07-14 13:50:21 +0100 | [diff] [blame] | 503 | } |
| 504 | |
Matt Arsenault | d08403b | 2021-05-19 22:06:14 -0400 | [diff] [blame] | 505 | MachineMemOperand *MachineFunction::getMachineMemOperand( |
| 506 | const MachineMemOperand *MMO, const MachinePointerInfo &PtrInfo, LLT Ty) { |
| 507 | return new (Allocator) |
| 508 | MachineMemOperand(PtrInfo, MMO->getFlags(), Ty, MMO->getBaseAlign(), |
| 509 | AAMDNodes(), nullptr, MMO->getSyncScopeID(), |
| 510 | MMO->getSuccessOrdering(), MMO->getFailureOrdering()); |
| 511 | } |
| 512 | |
Dan Gohman | 4ba0275 | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 513 | MachineMemOperand * |
| 514 | MachineFunction::getMachineMemOperand(const MachineMemOperand *MMO, |
Matt Arsenault | d08403b | 2021-05-19 22:06:14 -0400 | [diff] [blame] | 515 | int64_t Offset, LLT Ty) { |
Matt Arsenault | 4f8479b | 2019-01-31 01:49:58 +0000 | [diff] [blame] | 516 | const MachinePointerInfo &PtrInfo = MMO->getPointerInfo(); |
| 517 | |
| 518 | // If there is no pointer value, the offset isn't tracked so we need to adjust |
| 519 | // the base alignment. |
Guillaume Chatelet | e2bfff5 | 2020-03-27 13:51:59 +0000 | [diff] [blame] | 520 | Align Alignment = PtrInfo.V.isNull() |
| 521 | ? commonAlignment(MMO->getBaseAlign(), Offset) |
| 522 | : MMO->getBaseAlign(); |
Matt Arsenault | 4f8479b | 2019-01-31 01:49:58 +0000 | [diff] [blame] | 523 | |
Matt Arsenault | ad61143 | 2020-08-08 12:22:40 -0400 | [diff] [blame] | 524 | // Do not preserve ranges, since we don't necessarily know what the high bits |
| 525 | // are anymore. |
Eli Friedman | 4d7b2bb | 2021-06-21 16:34:02 -0700 | [diff] [blame] | 526 | return new (Allocator) MachineMemOperand( |
Matt Arsenault | d08403b | 2021-05-19 22:06:14 -0400 | [diff] [blame] | 527 | PtrInfo.getWithOffset(Offset), MMO->getFlags(), Ty, Alignment, |
Eli Friedman | 4d7b2bb | 2021-06-21 16:34:02 -0700 | [diff] [blame] | 528 | MMO->getAAInfo(), nullptr, MMO->getSyncScopeID(), |
| 529 | MMO->getSuccessOrdering(), MMO->getFailureOrdering()); |
Dan Gohman | 4ba0275 | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Hiroshi Inoue | d8d9f8a | 2017-08-01 03:32:15 +0000 | [diff] [blame] | 532 | MachineMemOperand * |
| 533 | MachineFunction::getMachineMemOperand(const MachineMemOperand *MMO, |
| 534 | const AAMDNodes &AAInfo) { |
| 535 | MachinePointerInfo MPI = MMO->getValue() ? |
| 536 | MachinePointerInfo(MMO->getValue(), MMO->getOffset()) : |
| 537 | MachinePointerInfo(MMO->getPseudoValue(), MMO->getOffset()); |
| 538 | |
Guillaume Chatelet | e2bfff5 | 2020-03-27 13:51:59 +0000 | [diff] [blame] | 539 | return new (Allocator) MachineMemOperand( |
Guillaume Chatelet | 8b16e93 | 2020-03-30 09:38:44 +0000 | [diff] [blame] | 540 | MPI, MMO->getFlags(), MMO->getSize(), MMO->getBaseAlign(), AAInfo, |
Eli Friedman | 4d7b2bb | 2021-06-21 16:34:02 -0700 | [diff] [blame] | 541 | MMO->getRanges(), MMO->getSyncScopeID(), MMO->getSuccessOrdering(), |
Guillaume Chatelet | e2bfff5 | 2020-03-27 13:51:59 +0000 | [diff] [blame] | 542 | MMO->getFailureOrdering()); |
Hiroshi Inoue | d8d9f8a | 2017-08-01 03:32:15 +0000 | [diff] [blame] | 543 | } |
| 544 | |
Simon Pilgrim | b92a472 | 2019-06-13 12:58:55 +0000 | [diff] [blame] | 545 | MachineMemOperand * |
| 546 | MachineFunction::getMachineMemOperand(const MachineMemOperand *MMO, |
| 547 | MachineMemOperand::Flags Flags) { |
| 548 | return new (Allocator) MachineMemOperand( |
Guillaume Chatelet | 8b16e93 | 2020-03-30 09:38:44 +0000 | [diff] [blame] | 549 | MMO->getPointerInfo(), Flags, MMO->getSize(), MMO->getBaseAlign(), |
Simon Pilgrim | b92a472 | 2019-06-13 12:58:55 +0000 | [diff] [blame] | 550 | MMO->getAAInfo(), MMO->getRanges(), MMO->getSyncScopeID(), |
Eli Friedman | 4d7b2bb | 2021-06-21 16:34:02 -0700 | [diff] [blame] | 551 | MMO->getSuccessOrdering(), MMO->getFailureOrdering()); |
Simon Pilgrim | b92a472 | 2019-06-13 12:58:55 +0000 | [diff] [blame] | 552 | } |
| 553 | |
Amy Huang | f93660a | 2019-10-28 14:53:32 -0700 | [diff] [blame] | 554 | MachineInstr::ExtraInfo *MachineFunction::createMIExtraInfo( |
| 555 | ArrayRef<MachineMemOperand *> MMOs, MCSymbol *PreInstrSymbol, |
Marco Elver | 94f3cfb | 2022-09-06 15:48:41 +0200 | [diff] [blame] | 556 | MCSymbol *PostInstrSymbol, MDNode *HeapAllocMarker, MDNode *PCSections, |
| 557 | uint32_t CFIType) { |
Chandler Carruth | 0cda7b9 | 2018-08-16 21:30:05 +0000 | [diff] [blame] | 558 | return MachineInstr::ExtraInfo::create(Allocator, MMOs, PreInstrSymbol, |
Sami Tolvanen | 72b40da | 2022-02-15 14:32:08 -0800 | [diff] [blame] | 559 | PostInstrSymbol, HeapAllocMarker, |
Marco Elver | 94f3cfb | 2022-09-06 15:48:41 +0200 | [diff] [blame] | 560 | PCSections, CFIType); |
Dan Gohman | d2f9d07 | 2009-10-09 18:10:05 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Alex Lorenz | 5304ab1 | 2015-07-21 16:59:53 +0000 | [diff] [blame] | 563 | const char *MachineFunction::createExternalSymbolName(StringRef Name) { |
| 564 | char *Dest = Allocator.Allocate<char>(Name.size() + 1); |
Fangrui Song | 6aa4878 | 2018-11-17 01:44:25 +0000 | [diff] [blame] | 565 | llvm::copy(Name, Dest); |
Alex Lorenz | 5304ab1 | 2015-07-21 16:59:53 +0000 | [diff] [blame] | 566 | Dest[Name.size()] = 0; |
| 567 | return Dest; |
| 568 | } |
| 569 | |
Matthias Braun | 5b535e7 | 2018-07-26 00:27:47 +0000 | [diff] [blame] | 570 | uint32_t *MachineFunction::allocateRegMask() { |
| 571 | unsigned NumRegs = getSubtarget().getRegisterInfo()->getNumRegs(); |
| 572 | unsigned Size = MachineOperand::getRegMaskSize(NumRegs); |
| 573 | uint32_t *Mask = Allocator.Allocate<uint32_t>(Size); |
| 574 | memset(Mask, 0, Size * sizeof(Mask[0])); |
| 575 | return Mask; |
| 576 | } |
| 577 | |
Eli Friedman | 098e258 | 2020-01-13 15:32:45 -0800 | [diff] [blame] | 578 | ArrayRef<int> MachineFunction::allocateShuffleMask(ArrayRef<int> Mask) { |
| 579 | int* AllocMask = Allocator.Allocate<int>(Mask.size()); |
| 580 | copy(Mask, AllocMask); |
| 581 | return {AllocMask, Mask.size()}; |
| 582 | } |
| 583 | |
Aaron Ballman | 7fced3f | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 584 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Yaron Keren | 33afa9a | 2016-01-29 20:50:44 +0000 | [diff] [blame] | 585 | LLVM_DUMP_METHOD void MachineFunction::dump() const { |
David Greene | 03fa688 | 2010-01-04 23:39:17 +0000 | [diff] [blame] | 586 | print(dbgs()); |
Dan Gohman | 1f4347b | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 587 | } |
Manman Ren | 4f061be | 2012-09-06 19:06:06 +0000 | [diff] [blame] | 588 | #endif |
Chris Lattner | a7f707c | 2002-10-30 00:48:05 +0000 | [diff] [blame] | 589 | |
Craig Topper | 53cc376 | 2012-08-22 06:07:19 +0000 | [diff] [blame] | 590 | StringRef MachineFunction::getName() const { |
Matthias Braun | 5863fee | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 591 | return getFunction().getName(); |
Craig Topper | 53cc376 | 2012-08-22 06:07:19 +0000 | [diff] [blame] | 592 | } |
| 593 | |
Matthias Braun | 25e9c81 | 2016-05-05 18:14:43 +0000 | [diff] [blame] | 594 | void MachineFunction::print(raw_ostream &OS, const SlotIndexes *Indexes) const { |
David Blaikie | ac7a490 | 2012-08-22 17:18:53 +0000 | [diff] [blame] | 595 | OS << "# Machine code for function " << getName() << ": "; |
Derek Schuff | 690a2c8 | 2016-03-29 20:28:20 +0000 | [diff] [blame] | 596 | getProperties().print(OS); |
Matthias Braun | 804dc54 | 2016-09-29 01:47:42 +0000 | [diff] [blame] | 597 | OS << '\n'; |
Chris Lattner | 5b841ff | 2002-12-28 20:37:16 +0000 | [diff] [blame] | 598 | |
| 599 | // Print Frame Information |
Dan Gohman | 1f4347b | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 600 | FrameInfo->print(*this, OS); |
Chad Rosier | be02a0a | 2012-06-19 23:37:57 +0000 | [diff] [blame] | 601 | |
Nate Begeman | 83e5f08 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 602 | // Print JumpTable Information |
Chris Lattner | 5b5cc06 | 2010-01-25 23:26:13 +0000 | [diff] [blame] | 603 | if (JumpTableInfo) |
| 604 | JumpTableInfo->print(OS); |
Chris Lattner | e151161 | 2003-01-13 00:23:03 +0000 | [diff] [blame] | 605 | |
| 606 | // Print Constant Pool |
Chris Lattner | b1d55db | 2009-08-23 01:12:47 +0000 | [diff] [blame] | 607 | ConstantPool->print(OS); |
Chad Rosier | be02a0a | 2012-06-19 23:37:57 +0000 | [diff] [blame] | 608 | |
Eric Christopher | 156c9f0 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 609 | const TargetRegisterInfo *TRI = getSubtarget().getRegisterInfo(); |
Chad Rosier | be02a0a | 2012-06-19 23:37:57 +0000 | [diff] [blame] | 610 | |
Matthijs Kooijman | 7167be4 | 2008-10-13 12:37:16 +0000 | [diff] [blame] | 611 | if (RegInfo && !RegInfo->livein_empty()) { |
Dan Gohman | 89871b6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 612 | OS << "Function Live Ins: "; |
Chris Lattner | 6534a42 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 613 | for (MachineRegisterInfo::livein_iterator |
| 614 | I = RegInfo->livein_begin(), E = RegInfo->livein_end(); I != E; ++I) { |
Francis Visoiu Mistrih | 8442f28 | 2017-11-28 12:42:37 +0000 | [diff] [blame] | 615 | OS << printReg(I->first, TRI); |
Chris Lattner | 02554c3 | 2006-05-16 05:55:30 +0000 | [diff] [blame] | 616 | if (I->second) |
Francis Visoiu Mistrih | 8442f28 | 2017-11-28 12:42:37 +0000 | [diff] [blame] | 617 | OS << " in " << printReg(I->second, TRI); |
Benjamin Kramer | 52ceb71 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 618 | if (std::next(I) != E) |
Dan Gohman | 89871b6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 619 | OS << ", "; |
Chris Lattner | 2818f79 | 2005-08-31 22:34:59 +0000 | [diff] [blame] | 620 | } |
Chris Lattner | b1d55db | 2009-08-23 01:12:47 +0000 | [diff] [blame] | 621 | OS << '\n'; |
Chris Lattner | 2818f79 | 2005-08-31 22:34:59 +0000 | [diff] [blame] | 622 | } |
Chad Rosier | be02a0a | 2012-06-19 23:37:57 +0000 | [diff] [blame] | 623 | |
Matthias Braun | 5863fee | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 624 | ModuleSlotTracker MST(getFunction().getParent()); |
| 625 | MST.incorporateFunction(getFunction()); |
Alexey Samsonov | ea3bb3e | 2014-04-30 18:29:51 +0000 | [diff] [blame] | 626 | for (const auto &BB : *this) { |
Dan Gohman | 89871b6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 627 | OS << '\n'; |
Francis Visoiu Mistrih | 7e0b176 | 2018-02-26 15:23:42 +0000 | [diff] [blame] | 628 | // If we print the whole function, print it at its most verbose level. |
| 629 | BB.print(OS, MST, Indexes, /*IsStandalone=*/true); |
Dan Gohman | 89871b6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 630 | } |
Brian Gaeke | 4bc33fe | 2004-03-29 21:58:31 +0000 | [diff] [blame] | 631 | |
David Blaikie | ac7a490 | 2012-08-22 17:18:53 +0000 | [diff] [blame] | 632 | OS << "\n# End machine code for function " << getName() << ".\n\n"; |
Chris Lattner | a7f707c | 2002-10-30 00:48:05 +0000 | [diff] [blame] | 633 | } |
| 634 | |
David Candler | 48a5619 | 2019-10-31 08:55:57 +0000 | [diff] [blame] | 635 | /// True if this function needs frame moves for debug or exceptions. |
| 636 | bool MachineFunction::needsFrameMoves() const { |
| 637 | return getMMI().hasDebugInfo() || |
| 638 | getTarget().Options.ForceDwarfFrameSection || |
| 639 | F.needsUnwindTableEntry(); |
| 640 | } |
| 641 | |
Alkis Evlogimenos | 8dccb67 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 642 | namespace llvm { |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 643 | |
Alkis Evlogimenos | b920999 | 2004-09-05 18:41:35 +0000 | [diff] [blame] | 644 | template<> |
| 645 | struct DOTGraphTraits<const MachineFunction*> : public DefaultDOTGraphTraits { |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 646 | DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {} |
Tobias Grosser | a2927b2 | 2009-11-30 12:38:13 +0000 | [diff] [blame] | 647 | |
Alkis Evlogimenos | b920999 | 2004-09-05 18:41:35 +0000 | [diff] [blame] | 648 | static std::string getGraphName(const MachineFunction *F) { |
Yaron Keren | 9b9119a | 2015-03-27 17:51:30 +0000 | [diff] [blame] | 649 | return ("CFG for '" + F->getName() + "' function").str(); |
Alkis Evlogimenos | 8dccb67 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Tobias Grosser | d968064 | 2009-11-30 12:38:47 +0000 | [diff] [blame] | 652 | std::string getNodeLabel(const MachineBasicBlock *Node, |
| 653 | const MachineFunction *Graph) { |
Chris Lattner | 167270f | 2009-08-23 03:13:20 +0000 | [diff] [blame] | 654 | std::string OutStr; |
| 655 | { |
| 656 | raw_string_ostream OSS(OutStr); |
Jakob Stoklund Olesen | eb5ac7d | 2010-10-30 01:26:19 +0000 | [diff] [blame] | 657 | |
| 658 | if (isSimple()) { |
Francis Visoiu Mistrih | 987af56 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 659 | OSS << printMBBReference(*Node); |
Jakob Stoklund Olesen | eb5ac7d | 2010-10-30 01:26:19 +0000 | [diff] [blame] | 660 | if (const BasicBlock *BB = Node->getBasicBlock()) |
| 661 | OSS << ": " << BB->getName(); |
| 662 | } else |
Chris Lattner | 167270f | 2009-08-23 03:13:20 +0000 | [diff] [blame] | 663 | Node->print(OSS); |
Alkis Evlogimenos | 8dccb67 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 664 | } |
Alkis Evlogimenos | b920999 | 2004-09-05 18:41:35 +0000 | [diff] [blame] | 665 | |
Alkis Evlogimenos | b920999 | 2004-09-05 18:41:35 +0000 | [diff] [blame] | 666 | if (OutStr[0] == '\n') OutStr.erase(OutStr.begin()); |
| 667 | |
| 668 | // Process string output to make it nicer... |
| 669 | for (unsigned i = 0; i != OutStr.length(); ++i) |
| 670 | if (OutStr[i] == '\n') { // Left justify |
| 671 | OutStr[i] = '\\'; |
| 672 | OutStr.insert(OutStr.begin()+i+1, 'l'); |
| 673 | } |
| 674 | return OutStr; |
| 675 | } |
| 676 | }; |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 677 | |
| 678 | } // end namespace llvm |
Alkis Evlogimenos | 8dccb67 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 679 | |
| 680 | void MachineFunction::viewCFG() const |
| 681 | { |
Jim Laskey | 8042f22 | 2005-10-12 12:09:05 +0000 | [diff] [blame] | 682 | #ifndef NDEBUG |
David Blaikie | ac7a490 | 2012-08-22 17:18:53 +0000 | [diff] [blame] | 683 | ViewGraph(this, "mf" + getName()); |
Reid Spencer | 8bc0706 | 2006-06-27 16:49:46 +0000 | [diff] [blame] | 684 | #else |
Dan Gohman | d2868a0 | 2010-07-07 17:28:45 +0000 | [diff] [blame] | 685 | errs() << "MachineFunction::viewCFG is only available in debug builds on " |
Daniel Dunbar | 84bf546 | 2009-08-23 08:50:52 +0000 | [diff] [blame] | 686 | << "systems with Graphviz or gv!\n"; |
Reid Spencer | 8bc0706 | 2006-06-27 16:49:46 +0000 | [diff] [blame] | 687 | #endif // NDEBUG |
Alkis Evlogimenos | 8dccb67 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | void MachineFunction::viewCFGOnly() const |
| 691 | { |
Owen Anderson | 5709d5a | 2009-06-24 17:37:09 +0000 | [diff] [blame] | 692 | #ifndef NDEBUG |
David Blaikie | ac7a490 | 2012-08-22 17:18:53 +0000 | [diff] [blame] | 693 | ViewGraph(this, "mf" + getName(), true); |
Owen Anderson | 5709d5a | 2009-06-24 17:37:09 +0000 | [diff] [blame] | 694 | #else |
Dan Gohman | d2868a0 | 2010-07-07 17:28:45 +0000 | [diff] [blame] | 695 | errs() << "MachineFunction::viewCFGOnly is only available in debug builds on " |
Daniel Dunbar | 84bf546 | 2009-08-23 08:50:52 +0000 | [diff] [blame] | 696 | << "systems with Graphviz or gv!\n"; |
Owen Anderson | 5709d5a | 2009-06-24 17:37:09 +0000 | [diff] [blame] | 697 | #endif // NDEBUG |
Alkis Evlogimenos | 8dccb67 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 698 | } |
| 699 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 700 | /// Add the specified physical register as a live-in value and |
Bob Wilson | 59fbc9a | 2009-04-20 18:36:57 +0000 | [diff] [blame] | 701 | /// create a corresponding virtual register for it. |
Matt Arsenault | 1bd8589 | 2020-05-19 13:01:19 -0400 | [diff] [blame] | 702 | Register MachineFunction::addLiveIn(MCRegister PReg, |
Devang Patel | d17405d | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 703 | const TargetRegisterClass *RC) { |
Evan Cheng | c5dd7ec | 2010-05-24 21:33:37 +0000 | [diff] [blame] | 704 | MachineRegisterInfo &MRI = getRegInfo(); |
Matt Arsenault | 1bd8589 | 2020-05-19 13:01:19 -0400 | [diff] [blame] | 705 | Register VReg = MRI.getLiveInVirtReg(PReg); |
Evan Cheng | c5dd7ec | 2010-05-24 21:33:37 +0000 | [diff] [blame] | 706 | if (VReg) { |
Quentin Colombet | f88a6cb | 2013-12-12 00:15:47 +0000 | [diff] [blame] | 707 | const TargetRegisterClass *VRegRC = MRI.getRegClass(VReg); |
| 708 | (void)VRegRC; |
| 709 | // A physical register can be added several times. |
| 710 | // Between two calls, the register class of the related virtual register |
| 711 | // may have been constrained to match some operation constraints. |
| 712 | // In that case, check that the current register class includes the |
| 713 | // physical register and is a sub class of the specified RC. |
| 714 | assert((VRegRC == RC || (VRegRC->contains(PReg) && |
| 715 | RC->hasSubClassEq(VRegRC))) && |
| 716 | "Register class mismatch!"); |
Evan Cheng | c5dd7ec | 2010-05-24 21:33:37 +0000 | [diff] [blame] | 717 | return VReg; |
| 718 | } |
| 719 | VReg = MRI.createVirtualRegister(RC); |
| 720 | MRI.addLiveIn(PReg, VReg); |
Bob Wilson | 59fbc9a | 2009-04-20 18:36:57 +0000 | [diff] [blame] | 721 | return VReg; |
| 722 | } |
| 723 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 724 | /// Return the MCSymbol for the specified non-empty jump table. |
Bill Wendling | 5c86eaf | 2010-06-29 22:34:52 +0000 | [diff] [blame] | 725 | /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a |
| 726 | /// normal 'L' label is returned. |
NAKAMURA Takumi | e82ebbb | 2014-06-25 12:40:56 +0000 | [diff] [blame] | 727 | MCSymbol *MachineFunction::getJTISymbol(unsigned JTI, MCContext &Ctx, |
Bill Wendling | 5c86eaf | 2010-06-29 22:34:52 +0000 | [diff] [blame] | 728 | bool isLinkerPrivate) const { |
Mehdi Amini | c0a24f6 | 2015-07-07 18:20:57 +0000 | [diff] [blame] | 729 | const DataLayout &DL = getDataLayout(); |
Chris Lattner | f2e86a7 | 2010-01-26 06:28:43 +0000 | [diff] [blame] | 730 | assert(JumpTableInfo && "No jump tables"); |
Chandler Carruth | d6b2d16 | 2010-01-27 10:27:10 +0000 | [diff] [blame] | 731 | assert(JTI < JumpTableInfo->getJumpTables().size() && "Invalid JTI!"); |
Chad Rosier | be02a0a | 2012-06-19 23:37:57 +0000 | [diff] [blame] | 732 | |
Mehdi Amini | a2120aa | 2016-10-01 05:57:55 +0000 | [diff] [blame] | 733 | StringRef Prefix = isLinkerPrivate ? DL.getLinkerPrivateGlobalPrefix() |
| 734 | : DL.getPrivateGlobalPrefix(); |
Alp Toker | bf3e686 | 2014-06-26 22:52:05 +0000 | [diff] [blame] | 735 | SmallString<60> Name; |
| 736 | raw_svector_ostream(Name) |
| 737 | << Prefix << "JTI" << getFunctionNumber() << '_' << JTI; |
Jim Grosbach | 3e3edb4 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 738 | return Ctx.getOrCreateSymbol(Name); |
Chris Lattner | f2e86a7 | 2010-01-26 06:28:43 +0000 | [diff] [blame] | 739 | } |
| 740 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 741 | /// Return a function-local symbol to represent the PIC base. |
Chris Lattner | eef1e04 | 2010-11-14 22:48:15 +0000 | [diff] [blame] | 742 | MCSymbol *MachineFunction::getPICBaseSymbol() const { |
Mehdi Amini | c0a24f6 | 2015-07-07 18:20:57 +0000 | [diff] [blame] | 743 | const DataLayout &DL = getDataLayout(); |
| 744 | return Ctx.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) + |
| 745 | Twine(getFunctionNumber()) + "$pb"); |
Chris Lattner | eef1e04 | 2010-11-14 22:48:15 +0000 | [diff] [blame] | 746 | } |
Chris Lattner | f2e86a7 | 2010-01-26 06:28:43 +0000 | [diff] [blame] | 747 | |
Matthias Braun | 1520f7a | 2016-12-01 19:32:15 +0000 | [diff] [blame] | 748 | /// \name Exception Handling |
| 749 | /// \{ |
| 750 | |
| 751 | LandingPadInfo & |
| 752 | MachineFunction::getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad) { |
| 753 | unsigned N = LandingPads.size(); |
| 754 | for (unsigned i = 0; i < N; ++i) { |
| 755 | LandingPadInfo &LP = LandingPads[i]; |
| 756 | if (LP.LandingPadBlock == LandingPad) |
| 757 | return LP; |
| 758 | } |
| 759 | |
| 760 | LandingPads.push_back(LandingPadInfo(LandingPad)); |
| 761 | return LandingPads[N]; |
| 762 | } |
| 763 | |
| 764 | void MachineFunction::addInvoke(MachineBasicBlock *LandingPad, |
| 765 | MCSymbol *BeginLabel, MCSymbol *EndLabel) { |
| 766 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
| 767 | LP.BeginLabels.push_back(BeginLabel); |
| 768 | LP.EndLabels.push_back(EndLabel); |
| 769 | } |
| 770 | |
| 771 | MCSymbol *MachineFunction::addLandingPad(MachineBasicBlock *LandingPad) { |
| 772 | MCSymbol *LandingPadLabel = Ctx.createTempSymbol(); |
| 773 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
| 774 | LP.LandingPadLabel = LandingPadLabel; |
Heejin Ahn | 8f1949a | 2018-09-25 19:56:44 +0000 | [diff] [blame] | 775 | |
| 776 | const Instruction *FirstI = LandingPad->getBasicBlock()->getFirstNonPHI(); |
| 777 | if (const auto *LPI = dyn_cast<LandingPadInst>(FirstI)) { |
James Y Knight | 2c6535d | 2023-01-06 13:26:03 -0500 | [diff] [blame] | 778 | // If there's no typeid list specified, then "cleanup" is implicit. |
| 779 | // Otherwise, id 0 is reserved for the cleanup action. |
| 780 | if (LPI->isCleanup() && LPI->getNumClauses() != 0) |
| 781 | LP.TypeIds.push_back(0); |
Heejin Ahn | 8f1949a | 2018-09-25 19:56:44 +0000 | [diff] [blame] | 782 | |
| 783 | // FIXME: New EH - Add the clauses in reverse order. This isn't 100% |
Heejin Ahn | ca24018 | 2018-09-29 09:22:25 +0000 | [diff] [blame] | 784 | // correct, but we need to do it this way because of how the DWARF EH |
| 785 | // emitter processes the clauses. |
Heejin Ahn | 8f1949a | 2018-09-25 19:56:44 +0000 | [diff] [blame] | 786 | for (unsigned I = LPI->getNumClauses(); I != 0; --I) { |
| 787 | Value *Val = LPI->getClause(I - 1); |
| 788 | if (LPI->isCatch(I - 1)) { |
James Y Knight | 2c6535d | 2023-01-06 13:26:03 -0500 | [diff] [blame] | 789 | LP.TypeIds.push_back( |
| 790 | getTypeIDFor(dyn_cast<GlobalValue>(Val->stripPointerCasts()))); |
Heejin Ahn | 8f1949a | 2018-09-25 19:56:44 +0000 | [diff] [blame] | 791 | } else { |
| 792 | // Add filters in a list. |
| 793 | auto *CVal = cast<Constant>(Val); |
James Y Knight | 2c6535d | 2023-01-06 13:26:03 -0500 | [diff] [blame] | 794 | SmallVector<unsigned, 4> FilterList; |
Kazu Hirata | f7812f0 | 2021-11-14 09:32:38 -0800 | [diff] [blame] | 795 | for (const Use &U : CVal->operands()) |
James Y Knight | 2c6535d | 2023-01-06 13:26:03 -0500 | [diff] [blame] | 796 | FilterList.push_back( |
| 797 | getTypeIDFor(cast<GlobalValue>(U->stripPointerCasts()))); |
Heejin Ahn | 8f1949a | 2018-09-25 19:56:44 +0000 | [diff] [blame] | 798 | |
James Y Knight | 2c6535d | 2023-01-06 13:26:03 -0500 | [diff] [blame] | 799 | LP.TypeIds.push_back(getFilterIDFor(FilterList)); |
Heejin Ahn | 8f1949a | 2018-09-25 19:56:44 +0000 | [diff] [blame] | 800 | } |
| 801 | } |
| 802 | |
Heejin Ahn | 19fb95c | 2018-10-25 23:55:10 +0000 | [diff] [blame] | 803 | } else if (const auto *CPI = dyn_cast<CatchPadInst>(FirstI)) { |
Kazu Hirata | 8fb0278 | 2022-10-17 10:15:10 -0700 | [diff] [blame] | 804 | for (unsigned I = CPI->arg_size(); I != 0; --I) { |
James Y Knight | 2c6535d | 2023-01-06 13:26:03 -0500 | [diff] [blame] | 805 | auto *TypeInfo = |
| 806 | dyn_cast<GlobalValue>(CPI->getArgOperand(I - 1)->stripPointerCasts()); |
| 807 | LP.TypeIds.push_back(getTypeIDFor(TypeInfo)); |
Heejin Ahn | 19fb95c | 2018-10-25 23:55:10 +0000 | [diff] [blame] | 808 | } |
Heejin Ahn | 8f1949a | 2018-09-25 19:56:44 +0000 | [diff] [blame] | 809 | |
| 810 | } else { |
| 811 | assert(isa<CleanupPadInst>(FirstI) && "Invalid landingpad!"); |
| 812 | } |
| 813 | |
Matthias Braun | 1520f7a | 2016-12-01 19:32:15 +0000 | [diff] [blame] | 814 | return LandingPadLabel; |
| 815 | } |
| 816 | |
Matthias Braun | 1520f7a | 2016-12-01 19:32:15 +0000 | [diff] [blame] | 817 | void MachineFunction::setCallSiteLandingPad(MCSymbol *Sym, |
| 818 | ArrayRef<unsigned> Sites) { |
| 819 | LPadToCallSiteMap[Sym].append(Sites.begin(), Sites.end()); |
| 820 | } |
| 821 | |
| 822 | unsigned MachineFunction::getTypeIDFor(const GlobalValue *TI) { |
| 823 | for (unsigned i = 0, N = TypeInfos.size(); i != N; ++i) |
| 824 | if (TypeInfos[i] == TI) return i + 1; |
| 825 | |
| 826 | TypeInfos.push_back(TI); |
| 827 | return TypeInfos.size(); |
| 828 | } |
| 829 | |
James Y Knight | 2c6535d | 2023-01-06 13:26:03 -0500 | [diff] [blame] | 830 | int MachineFunction::getFilterIDFor(ArrayRef<unsigned> TyIds) { |
Matthias Braun | 1520f7a | 2016-12-01 19:32:15 +0000 | [diff] [blame] | 831 | // If the new filter coincides with the tail of an existing filter, then |
| 832 | // re-use the existing filter. Folding filters more than this requires |
| 833 | // re-ordering filters and/or their elements - probably not worth it. |
Kazu Hirata | 44969dc | 2021-02-15 14:46:10 -0800 | [diff] [blame] | 834 | for (unsigned i : FilterEnds) { |
| 835 | unsigned j = TyIds.size(); |
Matthias Braun | 1520f7a | 2016-12-01 19:32:15 +0000 | [diff] [blame] | 836 | |
| 837 | while (i && j) |
| 838 | if (FilterIds[--i] != TyIds[--j]) |
| 839 | goto try_next; |
| 840 | |
| 841 | if (!j) |
| 842 | // The new filter coincides with range [i, end) of the existing filter. |
| 843 | return -(1 + i); |
| 844 | |
| 845 | try_next:; |
| 846 | } |
| 847 | |
| 848 | // Add the new filter. |
| 849 | int FilterID = -(1 + FilterIds.size()); |
| 850 | FilterIds.reserve(FilterIds.size() + TyIds.size() + 1); |
Kazu Hirata | dfce385 | 2020-12-28 19:55:16 -0800 | [diff] [blame] | 851 | llvm::append_range(FilterIds, TyIds); |
Matthias Braun | 1520f7a | 2016-12-01 19:32:15 +0000 | [diff] [blame] | 852 | FilterEnds.push_back(FilterIds.size()); |
| 853 | FilterIds.push_back(0); // terminator |
| 854 | return FilterID; |
| 855 | } |
| 856 | |
Reid Kleckner | 2f27189 | 2019-11-13 15:33:12 -0800 | [diff] [blame] | 857 | MachineFunction::CallSiteInfoMap::iterator |
| 858 | MachineFunction::getCallSiteInfo(const MachineInstr *MI) { |
Djordje Todorovic | eef604de | 2020-02-10 09:49:14 +0100 | [diff] [blame] | 859 | assert(MI->isCandidateForCallSiteEntry() && |
| 860 | "Call site info refers only to call (MI) candidates"); |
Djordje Todorovic | c60bf15 | 2020-02-20 13:43:01 +0100 | [diff] [blame] | 861 | |
Djordje Todorovic | 7caa825 | 2020-03-09 11:02:35 +0100 | [diff] [blame] | 862 | if (!Target.Options.EmitCallSiteInfo) |
Reid Kleckner | 2f27189 | 2019-11-13 15:33:12 -0800 | [diff] [blame] | 863 | return CallSitesInfo.end(); |
| 864 | return CallSitesInfo.find(MI); |
| 865 | } |
| 866 | |
Djordje Todorovic | 9081883 | 2020-02-27 11:44:53 +0100 | [diff] [blame] | 867 | /// Return the call machine instruction or find a call within bundle. |
| 868 | static const MachineInstr *getCallInstr(const MachineInstr *MI) { |
| 869 | if (!MI->isBundle()) |
| 870 | return MI; |
Djordje Todorovic | eef604de | 2020-02-10 09:49:14 +0100 | [diff] [blame] | 871 | |
Kazu Hirata | 6219a47 | 2022-07-17 01:33:28 -0700 | [diff] [blame] | 872 | for (const auto &BMI : make_range(getBundleStart(MI->getIterator()), |
| 873 | getBundleEnd(MI->getIterator()))) |
Djordje Todorovic | 9081883 | 2020-02-27 11:44:53 +0100 | [diff] [blame] | 874 | if (BMI.isCandidateForCallSiteEntry()) |
| 875 | return &BMI; |
Djordje Todorovic | b4e1c25 | 2019-06-27 13:10:29 +0000 | [diff] [blame] | 876 | |
Djordje Todorovic | 9081883 | 2020-02-27 11:44:53 +0100 | [diff] [blame] | 877 | llvm_unreachable("Unexpected bundle without a call site candidate"); |
Nikola Prica | 3c33bf7 | 2019-10-08 15:43:12 +0000 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | void MachineFunction::eraseCallSiteInfo(const MachineInstr *MI) { |
Djordje Todorovic | 9081883 | 2020-02-27 11:44:53 +0100 | [diff] [blame] | 881 | assert(MI->shouldUpdateCallSiteInfo() && |
| 882 | "Call site info refers only to call (MI) candidates or " |
| 883 | "candidates inside bundles"); |
| 884 | |
| 885 | const MachineInstr *CallMI = getCallInstr(MI); |
| 886 | CallSiteInfoMap::iterator CSIt = getCallSiteInfo(CallMI); |
Nikola Prica | 3c33bf7 | 2019-10-08 15:43:12 +0000 | [diff] [blame] | 887 | if (CSIt == CallSitesInfo.end()) |
| 888 | return; |
| 889 | CallSitesInfo.erase(CSIt); |
| 890 | } |
| 891 | |
| 892 | void MachineFunction::copyCallSiteInfo(const MachineInstr *Old, |
| 893 | const MachineInstr *New) { |
Djordje Todorovic | 9081883 | 2020-02-27 11:44:53 +0100 | [diff] [blame] | 894 | assert(Old->shouldUpdateCallSiteInfo() && |
| 895 | "Call site info refers only to call (MI) candidates or " |
| 896 | "candidates inside bundles"); |
Djordje Todorovic | eef604de | 2020-02-10 09:49:14 +0100 | [diff] [blame] | 897 | |
| 898 | if (!New->isCandidateForCallSiteEntry()) |
| 899 | return eraseCallSiteInfo(Old); |
Nikola Prica | 3c33bf7 | 2019-10-08 15:43:12 +0000 | [diff] [blame] | 900 | |
Djordje Todorovic | 9081883 | 2020-02-27 11:44:53 +0100 | [diff] [blame] | 901 | const MachineInstr *OldCallMI = getCallInstr(Old); |
| 902 | CallSiteInfoMap::iterator CSIt = getCallSiteInfo(OldCallMI); |
Nikola Prica | 3c33bf7 | 2019-10-08 15:43:12 +0000 | [diff] [blame] | 903 | if (CSIt == CallSitesInfo.end()) |
| 904 | return; |
| 905 | |
| 906 | CallSiteInfo CSInfo = CSIt->second; |
| 907 | CallSitesInfo[New] = CSInfo; |
Djordje Todorovic | b4e1c25 | 2019-06-27 13:10:29 +0000 | [diff] [blame] | 908 | } |
| 909 | |
Djordje Todorovic | 9081883 | 2020-02-27 11:44:53 +0100 | [diff] [blame] | 910 | void MachineFunction::moveCallSiteInfo(const MachineInstr *Old, |
| 911 | const MachineInstr *New) { |
| 912 | assert(Old->shouldUpdateCallSiteInfo() && |
| 913 | "Call site info refers only to call (MI) candidates or " |
| 914 | "candidates inside bundles"); |
| 915 | |
| 916 | if (!New->isCandidateForCallSiteEntry()) |
| 917 | return eraseCallSiteInfo(Old); |
| 918 | |
| 919 | const MachineInstr *OldCallMI = getCallInstr(Old); |
| 920 | CallSiteInfoMap::iterator CSIt = getCallSiteInfo(OldCallMI); |
| 921 | if (CSIt == CallSitesInfo.end()) |
| 922 | return; |
| 923 | |
| 924 | CallSiteInfo CSInfo = std::move(CSIt->second); |
| 925 | CallSitesInfo.erase(CSIt); |
| 926 | CallSitesInfo[New] = CSInfo; |
| 927 | } |
| 928 | |
Jeremy Morse | c3f1c28 | 2020-10-14 10:47:44 +0100 | [diff] [blame] | 929 | void MachineFunction::setDebugInstrNumberingCount(unsigned Num) { |
| 930 | DebugInstrNumberingCount = Num; |
| 931 | } |
| 932 | |
Jeremy Morse | 3cfcd54 | 2020-10-15 11:20:29 +0100 | [diff] [blame] | 933 | void MachineFunction::makeDebugValueSubstitution(DebugInstrOperandPair A, |
Jeremy Morse | 21b9418 | 2021-07-01 10:59:22 +0100 | [diff] [blame] | 934 | DebugInstrOperandPair B, |
| 935 | unsigned Subreg) { |
| 936 | // Catch any accidental self-loops. |
| 937 | assert(A.first != B.first); |
Jeremy Morse | a4f9374 | 2021-10-25 15:09:42 +0100 | [diff] [blame] | 938 | // Don't allow any substitutions _from_ the memory operand number. |
| 939 | assert(A.second != DebugOperandMemNumber); |
| 940 | |
Jeremy Morse | 4af1bec | 2021-07-09 15:32:30 +0100 | [diff] [blame] | 941 | DebugValueSubstitutions.push_back({A, B, Subreg}); |
Jeremy Morse | 3cfcd54 | 2020-10-15 11:20:29 +0100 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | void MachineFunction::substituteDebugValuesForInst(const MachineInstr &Old, |
Jeremy Morse | 06e15d0 | 2020-10-21 14:28:28 +0100 | [diff] [blame] | 945 | MachineInstr &New, |
| 946 | unsigned MaxOperand) { |
Jeremy Morse | 3cfcd54 | 2020-10-15 11:20:29 +0100 | [diff] [blame] | 947 | // If the Old instruction wasn't tracked at all, there is no work to do. |
| 948 | unsigned OldInstrNum = Old.peekDebugInstrNum(); |
| 949 | if (!OldInstrNum) |
| 950 | return; |
| 951 | |
| 952 | // Iterate over all operands looking for defs to create substitutions for. |
| 953 | // Avoid creating new instr numbers unless we create a new substitution. |
| 954 | // While this has no functional effect, it risks confusing someone reading |
| 955 | // MIR output. |
Jeremy Morse | 06e15d0 | 2020-10-21 14:28:28 +0100 | [diff] [blame] | 956 | // Examine all the operands, or the first N specified by the caller. |
| 957 | MaxOperand = std::min(MaxOperand, Old.getNumOperands()); |
Jeremy Morse | 9aaf24c | 2021-07-20 10:43:21 +0100 | [diff] [blame] | 958 | for (unsigned int I = 0; I < MaxOperand; ++I) { |
Jeremy Morse | 3cfcd54 | 2020-10-15 11:20:29 +0100 | [diff] [blame] | 959 | const auto &OldMO = Old.getOperand(I); |
Jeremy Morse | 06e15d0 | 2020-10-21 14:28:28 +0100 | [diff] [blame] | 960 | auto &NewMO = New.getOperand(I); |
| 961 | (void)NewMO; |
Jeremy Morse | 3cfcd54 | 2020-10-15 11:20:29 +0100 | [diff] [blame] | 962 | |
| 963 | if (!OldMO.isReg() || !OldMO.isDef()) |
| 964 | continue; |
Jeremy Morse | 06e15d0 | 2020-10-21 14:28:28 +0100 | [diff] [blame] | 965 | assert(NewMO.isDef()); |
Jeremy Morse | 3cfcd54 | 2020-10-15 11:20:29 +0100 | [diff] [blame] | 966 | |
| 967 | unsigned NewInstrNum = New.getDebugInstrNum(); |
| 968 | makeDebugValueSubstitution(std::make_pair(OldInstrNum, I), |
| 969 | std::make_pair(NewInstrNum, I)); |
| 970 | } |
| 971 | } |
| 972 | |
Jeremy Morse | e11d27e | 2022-05-03 09:42:27 +0100 | [diff] [blame] | 973 | auto MachineFunction::salvageCopySSA( |
| 974 | MachineInstr &MI, DenseMap<Register, DebugInstrOperandPair> &DbgPHICache) |
| 975 | -> DebugInstrOperandPair { |
| 976 | const TargetInstrInfo &TII = *getSubtarget().getInstrInfo(); |
| 977 | |
| 978 | // Check whether this copy-like instruction has already been salvaged into |
| 979 | // an operand pair. |
| 980 | Register Dest; |
| 981 | if (auto CopyDstSrc = TII.isCopyInstr(MI)) { |
| 982 | Dest = CopyDstSrc->Destination->getReg(); |
| 983 | } else { |
| 984 | assert(MI.isSubregToReg()); |
| 985 | Dest = MI.getOperand(0).getReg(); |
| 986 | } |
| 987 | |
| 988 | auto CacheIt = DbgPHICache.find(Dest); |
| 989 | if (CacheIt != DbgPHICache.end()) |
| 990 | return CacheIt->second; |
| 991 | |
| 992 | // Calculate the instruction number to use, or install a DBG_PHI. |
| 993 | auto OperandPair = salvageCopySSAImpl(MI); |
| 994 | DbgPHICache.insert({Dest, OperandPair}); |
| 995 | return OperandPair; |
| 996 | } |
| 997 | |
| 998 | auto MachineFunction::salvageCopySSAImpl(MachineInstr &MI) |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 999 | -> DebugInstrOperandPair { |
| 1000 | MachineRegisterInfo &MRI = getRegInfo(); |
| 1001 | const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo(); |
| 1002 | const TargetInstrInfo &TII = *getSubtarget().getInstrInfo(); |
| 1003 | |
| 1004 | // Chase the value read by a copy-like instruction back to the instruction |
| 1005 | // that ultimately _defines_ that value. This may pass: |
| 1006 | // * Through multiple intermediate copies, including subregister moves / |
| 1007 | // copies, |
| 1008 | // * Copies from physical registers that must then be traced back to the |
| 1009 | // defining instruction, |
| 1010 | // * Or, physical registers may be live-in to (only) the entry block, which |
| 1011 | // requires a DBG_PHI to be created. |
| 1012 | // We can pursue this problem in that order: trace back through copies, |
| 1013 | // optionally through a physical register, to a defining instruction. We |
| 1014 | // should never move from physreg to vreg. As we're still in SSA form, no need |
| 1015 | // to worry about partial definitions of registers. |
| 1016 | |
| 1017 | // Helper lambda to interpret a copy-like instruction. Takes instruction, |
| 1018 | // returns the register read and any subregister identifying which part is |
| 1019 | // read. |
| 1020 | auto GetRegAndSubreg = |
| 1021 | [&](const MachineInstr &Cpy) -> std::pair<Register, unsigned> { |
| 1022 | Register NewReg, OldReg; |
| 1023 | unsigned SubReg; |
| 1024 | if (Cpy.isCopy()) { |
| 1025 | OldReg = Cpy.getOperand(0).getReg(); |
| 1026 | NewReg = Cpy.getOperand(1).getReg(); |
| 1027 | SubReg = Cpy.getOperand(1).getSubReg(); |
| 1028 | } else if (Cpy.isSubregToReg()) { |
| 1029 | OldReg = Cpy.getOperand(0).getReg(); |
| 1030 | NewReg = Cpy.getOperand(2).getReg(); |
| 1031 | SubReg = Cpy.getOperand(3).getImm(); |
| 1032 | } else { |
| 1033 | auto CopyDetails = *TII.isCopyInstr(Cpy); |
| 1034 | const MachineOperand &Src = *CopyDetails.Source; |
| 1035 | const MachineOperand &Dest = *CopyDetails.Destination; |
| 1036 | OldReg = Dest.getReg(); |
| 1037 | NewReg = Src.getReg(); |
| 1038 | SubReg = Src.getSubReg(); |
| 1039 | } |
| 1040 | |
| 1041 | return {NewReg, SubReg}; |
| 1042 | }; |
| 1043 | |
| 1044 | // First seek either the defining instruction, or a copy from a physreg. |
| 1045 | // During search, the current state is the current copy instruction, and which |
| 1046 | // register we've read. Accumulate qualifying subregisters into SubregsSeen; |
| 1047 | // deal with those later. |
| 1048 | auto State = GetRegAndSubreg(MI); |
| 1049 | auto CurInst = MI.getIterator(); |
| 1050 | SmallVector<unsigned, 4> SubregsSeen; |
| 1051 | while (true) { |
| 1052 | // If we've found a copy from a physreg, first portion of search is over. |
| 1053 | if (!State.first.isVirtual()) |
| 1054 | break; |
| 1055 | |
| 1056 | // Record any subregister qualifier. |
| 1057 | if (State.second) |
| 1058 | SubregsSeen.push_back(State.second); |
| 1059 | |
| 1060 | assert(MRI.hasOneDef(State.first)); |
| 1061 | MachineInstr &Inst = *MRI.def_begin(State.first)->getParent(); |
| 1062 | CurInst = Inst.getIterator(); |
| 1063 | |
| 1064 | // Any non-copy instruction is the defining instruction we're seeking. |
| 1065 | if (!Inst.isCopyLike() && !TII.isCopyInstr(Inst)) |
| 1066 | break; |
| 1067 | State = GetRegAndSubreg(Inst); |
| 1068 | }; |
| 1069 | |
| 1070 | // Helper lambda to apply additional subregister substitutions to a known |
| 1071 | // instruction/operand pair. Adds new (fake) substitutions so that we can |
| 1072 | // record the subregister. FIXME: this isn't very space efficient if multiple |
| 1073 | // values are tracked back through the same copies; cache something later. |
| 1074 | auto ApplySubregisters = |
| 1075 | [&](DebugInstrOperandPair P) -> DebugInstrOperandPair { |
| 1076 | for (unsigned Subreg : reverse(SubregsSeen)) { |
| 1077 | // Fetch a new instruction number, not attached to an actual instruction. |
| 1078 | unsigned NewInstrNumber = getNewDebugInstrNum(); |
| 1079 | // Add a substitution from the "new" number to the known one, with a |
| 1080 | // qualifying subreg. |
| 1081 | makeDebugValueSubstitution({NewInstrNumber, 0}, P, Subreg); |
| 1082 | // Return the new number; to find the underlying value, consumers need to |
| 1083 | // deal with the qualifying subreg. |
| 1084 | P = {NewInstrNumber, 0}; |
| 1085 | } |
| 1086 | return P; |
| 1087 | }; |
| 1088 | |
| 1089 | // If we managed to find the defining instruction after COPYs, return an |
| 1090 | // instruction / operand pair after adding subregister qualifiers. |
| 1091 | if (State.first.isVirtual()) { |
| 1092 | // Virtual register def -- we can just look up where this happens. |
| 1093 | MachineInstr *Inst = MRI.def_begin(State.first)->getParent(); |
Jay Foad | 9d72566 | 2023-05-24 14:57:23 +0100 | [diff] [blame] | 1094 | for (auto &MO : Inst->all_defs()) { |
| 1095 | if (MO.getReg() != State.first) |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1096 | continue; |
Jay Foad | 6501ea0 | 2023-02-03 09:42:25 +0000 | [diff] [blame] | 1097 | return ApplySubregisters({Inst->getDebugInstrNum(), MO.getOperandNo()}); |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | llvm_unreachable("Vreg def with no corresponding operand?"); |
| 1101 | } |
| 1102 | |
| 1103 | // Our search ended in a copy from a physreg: walk back up the function |
| 1104 | // looking for whatever defines the physreg. |
| 1105 | assert(CurInst->isCopyLike() || TII.isCopyInstr(*CurInst)); |
| 1106 | State = GetRegAndSubreg(*CurInst); |
| 1107 | Register RegToSeek = State.first; |
| 1108 | |
| 1109 | auto RMII = CurInst->getReverseIterator(); |
| 1110 | auto PrevInstrs = make_range(RMII, CurInst->getParent()->instr_rend()); |
| 1111 | for (auto &ToExamine : PrevInstrs) { |
Jay Foad | 9d72566 | 2023-05-24 14:57:23 +0100 | [diff] [blame] | 1112 | for (auto &MO : ToExamine.all_defs()) { |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1113 | // Test for operand that defines something aliasing RegToSeek. |
Jay Foad | 9d72566 | 2023-05-24 14:57:23 +0100 | [diff] [blame] | 1114 | if (!TRI.regsOverlap(RegToSeek, MO.getReg())) |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1115 | continue; |
| 1116 | |
| 1117 | return ApplySubregisters( |
Jay Foad | 6501ea0 | 2023-02-03 09:42:25 +0000 | [diff] [blame] | 1118 | {ToExamine.getDebugInstrNum(), MO.getOperandNo()}); |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | |
Jeremy Morse | 1f97745 | 2021-07-26 15:00:08 +0100 | [diff] [blame] | 1122 | MachineBasicBlock &InsertBB = *CurInst->getParent(); |
| 1123 | |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1124 | // We reached the start of the block before finding a defining instruction. |
Jeremy Morse | a5cf465 | 2022-03-04 16:39:22 +0000 | [diff] [blame] | 1125 | // There are numerous scenarios where this can happen: |
| 1126 | // * Constant physical registers, |
| 1127 | // * Several intrinsics that allow LLVM-IR to read arbitary registers, |
| 1128 | // * Arguments in the entry block, |
| 1129 | // * Exception handling landing pads. |
| 1130 | // Validating all of them is too difficult, so just insert a DBG_PHI reading |
| 1131 | // the variable value at this position, rather than checking it makes sense. |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1132 | |
| 1133 | // Create DBG_PHI for specified physreg. |
Jeremy Morse | 1f97745 | 2021-07-26 15:00:08 +0100 | [diff] [blame] | 1134 | auto Builder = BuildMI(InsertBB, InsertBB.getFirstNonPHI(), DebugLoc(), |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1135 | TII.get(TargetOpcode::DBG_PHI)); |
Jack Andersen | 67d9656 | 2021-10-07 16:02:30 +0100 | [diff] [blame] | 1136 | Builder.addReg(State.first); |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1137 | unsigned NewNum = getNewDebugInstrNum(); |
| 1138 | Builder.addImm(NewNum); |
| 1139 | return ApplySubregisters({NewNum, 0u}); |
| 1140 | } |
| 1141 | |
| 1142 | void MachineFunction::finalizeDebugInstrRefs() { |
| 1143 | auto *TII = getSubtarget().getInstrInfo(); |
| 1144 | |
Jeremy Morse | 66998b3 | 2021-11-24 10:20:03 +0000 | [diff] [blame] | 1145 | auto MakeUndefDbgValue = [&](MachineInstr &MI) { |
Stephen Tozer | 307857a | 2022-09-15 11:26:57 +0100 | [diff] [blame] | 1146 | const MCInstrDesc &RefII = TII->get(TargetOpcode::DBG_VALUE_LIST); |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1147 | MI.setDesc(RefII); |
Stephen Tozer | 64c93c9 | 2023-01-03 18:13:31 +0000 | [diff] [blame] | 1148 | MI.setDebugValueUndef(); |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1149 | }; |
| 1150 | |
Jeremy Morse | e11d27e | 2022-05-03 09:42:27 +0100 | [diff] [blame] | 1151 | DenseMap<Register, DebugInstrOperandPair> ArgDbgPHIs; |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1152 | for (auto &MBB : *this) { |
| 1153 | for (auto &MI : MBB) { |
Stephen Tozer | 64c93c9 | 2023-01-03 18:13:31 +0000 | [diff] [blame] | 1154 | if (!MI.isDebugRef()) |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1155 | continue; |
| 1156 | |
Stephen Tozer | 64c93c9 | 2023-01-03 18:13:31 +0000 | [diff] [blame] | 1157 | bool IsValidRef = true; |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1158 | |
Stephen Tozer | 64c93c9 | 2023-01-03 18:13:31 +0000 | [diff] [blame] | 1159 | for (MachineOperand &MO : MI.debug_operands()) { |
| 1160 | if (!MO.isReg()) |
| 1161 | continue; |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1162 | |
Stephen Tozer | 64c93c9 | 2023-01-03 18:13:31 +0000 | [diff] [blame] | 1163 | Register Reg = MO.getReg(); |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1164 | |
Stephen Tozer | 64c93c9 | 2023-01-03 18:13:31 +0000 | [diff] [blame] | 1165 | // Some vregs can be deleted as redundant in the meantime. Mark those |
| 1166 | // as DBG_VALUE $noreg. Additionally, some normal instructions are |
| 1167 | // quickly deleted, leaving dangling references to vregs with no def. |
| 1168 | if (Reg == 0 || !RegInfo->hasOneDef(Reg)) { |
| 1169 | IsValidRef = false; |
| 1170 | break; |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1171 | } |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1172 | |
Stephen Tozer | 64c93c9 | 2023-01-03 18:13:31 +0000 | [diff] [blame] | 1173 | assert(Reg.isVirtual()); |
| 1174 | MachineInstr &DefMI = *RegInfo->def_instr_begin(Reg); |
| 1175 | |
| 1176 | // If we've found a copy-like instruction, follow it back to the |
| 1177 | // instruction that defines the source value, see salvageCopySSA docs |
| 1178 | // for why this is important. |
| 1179 | if (DefMI.isCopyLike() || TII->isCopyInstr(DefMI)) { |
| 1180 | auto Result = salvageCopySSA(DefMI, ArgDbgPHIs); |
| 1181 | MO.ChangeToDbgInstrRef(Result.first, Result.second); |
| 1182 | } else { |
| 1183 | // Otherwise, identify the operand number that the VReg refers to. |
| 1184 | unsigned OperandIdx = 0; |
| 1185 | for (const auto &DefMO : DefMI.operands()) { |
| 1186 | if (DefMO.isReg() && DefMO.isDef() && DefMO.getReg() == Reg) |
| 1187 | break; |
| 1188 | ++OperandIdx; |
| 1189 | } |
| 1190 | assert(OperandIdx < DefMI.getNumOperands()); |
| 1191 | |
| 1192 | // Morph this instr ref to point at the given instruction and operand. |
| 1193 | unsigned ID = DefMI.getDebugInstrNum(); |
| 1194 | MO.ChangeToDbgInstrRef(ID, OperandIdx); |
| 1195 | } |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1196 | } |
Stephen Tozer | 64c93c9 | 2023-01-03 18:13:31 +0000 | [diff] [blame] | 1197 | |
| 1198 | if (!IsValidRef) |
| 1199 | MakeUndefDbgValue(MI); |
Jeremy Morse | b913396 | 2021-06-02 15:14:37 +0100 | [diff] [blame] | 1200 | } |
| 1201 | } |
| 1202 | } |
| 1203 | |
Jeremy Morse | d0f58ba | 2023-01-20 14:14:39 +0000 | [diff] [blame] | 1204 | bool MachineFunction::shouldUseDebugInstrRef() const { |
Jeremy Morse | 97b8878 | 2021-08-25 14:56:05 +0100 | [diff] [blame] | 1205 | // Disable instr-ref at -O0: it's very slow (in compile time). We can still |
| 1206 | // have optimized code inlined into this unoptimized code, however with |
| 1207 | // fewer and less aggressive optimizations happening, coverage and accuracy |
| 1208 | // should not suffer. |
Arthur Eubanks | 254c2e5 | 2023-09-14 14:10:14 -0700 | [diff] [blame] | 1209 | if (getTarget().getOptLevel() == CodeGenOptLevel::None) |
Jeremy Morse | 97b8878 | 2021-08-25 14:56:05 +0100 | [diff] [blame] | 1210 | return false; |
| 1211 | |
| 1212 | // Don't use instr-ref if this function is marked optnone. |
| 1213 | if (F.hasFnAttribute(Attribute::OptimizeNone)) |
| 1214 | return false; |
| 1215 | |
Jeremy Morse | 5550704 | 2022-01-12 12:35:36 +0000 | [diff] [blame] | 1216 | if (llvm::debuginfoShouldUseDebugInstrRef(getTarget().getTargetTriple())) |
Jeremy Morse | 97b8878 | 2021-08-25 14:56:05 +0100 | [diff] [blame] | 1217 | return true; |
| 1218 | |
| 1219 | return false; |
| 1220 | } |
| 1221 | |
Jeremy Morse | d0f58ba | 2023-01-20 14:14:39 +0000 | [diff] [blame] | 1222 | bool MachineFunction::useDebugInstrRef() const { |
| 1223 | return UseDebugInstrRef; |
| 1224 | } |
| 1225 | |
| 1226 | void MachineFunction::setUseDebugInstrRef(bool Use) { |
| 1227 | UseDebugInstrRef = Use; |
| 1228 | } |
| 1229 | |
Jeremy Morse | a4f9374 | 2021-10-25 15:09:42 +0100 | [diff] [blame] | 1230 | // Use one million as a high / reserved number. |
| 1231 | const unsigned MachineFunction::DebugOperandMemNumber = 1000000; |
| 1232 | |
Matthias Braun | 1520f7a | 2016-12-01 19:32:15 +0000 | [diff] [blame] | 1233 | /// \} |
| 1234 | |
Chris Lattner | 5b841ff | 2002-12-28 20:37:16 +0000 | [diff] [blame] | 1235 | //===----------------------------------------------------------------------===// |
Nate Begeman | 83e5f08 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1236 | // MachineJumpTableInfo implementation |
| 1237 | //===----------------------------------------------------------------------===// |
| 1238 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 1239 | /// Return the size of each entry in the jump table. |
Micah Villmow | fda694e | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 1240 | unsigned MachineJumpTableInfo::getEntrySize(const DataLayout &TD) const { |
Chris Lattner | 5b5cc06 | 2010-01-25 23:26:13 +0000 | [diff] [blame] | 1241 | // The size of a jump table entry is 4 bytes unless the entry is just the |
| 1242 | // address of a block, in which case it is the pointer size. |
| 1243 | switch (getEntryKind()) { |
| 1244 | case MachineJumpTableInfo::EK_BlockAddress: |
Chandler Carruth | 5893488 | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 1245 | return TD.getPointerSize(); |
Akira Hatanaka | fd156ff | 2012-02-03 04:33:00 +0000 | [diff] [blame] | 1246 | case MachineJumpTableInfo::EK_GPRel64BlockAddress: |
Arthur Eubanks | 695e018 | 2023-08-31 10:13:20 -0700 | [diff] [blame] | 1247 | case MachineJumpTableInfo::EK_LabelDifference64: |
Akira Hatanaka | fd156ff | 2012-02-03 04:33:00 +0000 | [diff] [blame] | 1248 | return 8; |
Chris Lattner | 5b5cc06 | 2010-01-25 23:26:13 +0000 | [diff] [blame] | 1249 | case MachineJumpTableInfo::EK_GPRel32BlockAddress: |
| 1250 | case MachineJumpTableInfo::EK_LabelDifference32: |
Chris Lattner | 0d82d76 | 2010-01-26 04:05:28 +0000 | [diff] [blame] | 1251 | case MachineJumpTableInfo::EK_Custom32: |
Chris Lattner | 5b5cc06 | 2010-01-25 23:26:13 +0000 | [diff] [blame] | 1252 | return 4; |
Richard Osborne | ce2762c | 2010-03-11 14:58:16 +0000 | [diff] [blame] | 1253 | case MachineJumpTableInfo::EK_Inline: |
| 1254 | return 0; |
Chris Lattner | 5b5cc06 | 2010-01-25 23:26:13 +0000 | [diff] [blame] | 1255 | } |
Craig Topper | e8a18f3 | 2012-02-06 08:17:43 +0000 | [diff] [blame] | 1256 | llvm_unreachable("Unknown jump table encoding!"); |
Chris Lattner | 5b5cc06 | 2010-01-25 23:26:13 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 1259 | /// Return the alignment of each entry in the jump table. |
Micah Villmow | fda694e | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 1260 | unsigned MachineJumpTableInfo::getEntryAlignment(const DataLayout &TD) const { |
Chris Lattner | 5b5cc06 | 2010-01-25 23:26:13 +0000 | [diff] [blame] | 1261 | // The alignment of a jump table entry is the alignment of int32 unless the |
| 1262 | // entry is just the address of a block, in which case it is the pointer |
| 1263 | // alignment. |
| 1264 | switch (getEntryKind()) { |
| 1265 | case MachineJumpTableInfo::EK_BlockAddress: |
Guillaume Chatelet | c5dbe67 | 2019-09-23 12:41:36 +0000 | [diff] [blame] | 1266 | return TD.getPointerABIAlignment(0).value(); |
Akira Hatanaka | fd156ff | 2012-02-03 04:33:00 +0000 | [diff] [blame] | 1267 | case MachineJumpTableInfo::EK_GPRel64BlockAddress: |
Arthur Eubanks | 695e018 | 2023-08-31 10:13:20 -0700 | [diff] [blame] | 1268 | case MachineJumpTableInfo::EK_LabelDifference64: |
Guillaume Chatelet | c5dbe67 | 2019-09-23 12:41:36 +0000 | [diff] [blame] | 1269 | return TD.getABIIntegerTypeAlignment(64).value(); |
Chris Lattner | 5b5cc06 | 2010-01-25 23:26:13 +0000 | [diff] [blame] | 1270 | case MachineJumpTableInfo::EK_GPRel32BlockAddress: |
| 1271 | case MachineJumpTableInfo::EK_LabelDifference32: |
Chris Lattner | 0d82d76 | 2010-01-26 04:05:28 +0000 | [diff] [blame] | 1272 | case MachineJumpTableInfo::EK_Custom32: |
Guillaume Chatelet | c5dbe67 | 2019-09-23 12:41:36 +0000 | [diff] [blame] | 1273 | return TD.getABIIntegerTypeAlignment(32).value(); |
Richard Osborne | ce2762c | 2010-03-11 14:58:16 +0000 | [diff] [blame] | 1274 | case MachineJumpTableInfo::EK_Inline: |
| 1275 | return 1; |
Chris Lattner | 5b5cc06 | 2010-01-25 23:26:13 +0000 | [diff] [blame] | 1276 | } |
Craig Topper | e8a18f3 | 2012-02-06 08:17:43 +0000 | [diff] [blame] | 1277 | llvm_unreachable("Unknown jump table encoding!"); |
Chris Lattner | 5b5cc06 | 2010-01-25 23:26:13 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 1280 | /// Create a new jump table entry in the jump table info. |
Bob Wilson | ab8df3d | 2010-03-18 18:42:41 +0000 | [diff] [blame] | 1281 | unsigned MachineJumpTableInfo::createJumpTableIndex( |
Chris Lattner | 0b91ab9 | 2006-10-28 18:17:09 +0000 | [diff] [blame] | 1282 | const std::vector<MachineBasicBlock*> &DestBBs) { |
Chris Lattner | cbe53df | 2006-10-28 18:11:20 +0000 | [diff] [blame] | 1283 | assert(!DestBBs.empty() && "Cannot create an empty jump table!"); |
Nate Begeman | 83e5f08 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1284 | JumpTables.push_back(MachineJumpTableEntry(DestBBs)); |
| 1285 | return JumpTables.size()-1; |
| 1286 | } |
| 1287 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 1288 | /// If Old is the target of any jump tables, update the jump tables to branch |
| 1289 | /// to New instead. |
Chris Lattner | 80a6849 | 2010-01-26 05:58:28 +0000 | [diff] [blame] | 1290 | bool MachineJumpTableInfo::ReplaceMBBInJumpTables(MachineBasicBlock *Old, |
| 1291 | MachineBasicBlock *New) { |
Dan Gohman | 557b391 | 2009-04-15 01:18:49 +0000 | [diff] [blame] | 1292 | assert(Old != New && "Not making a change?"); |
| 1293 | bool MadeChange = false; |
Jim Grosbach | 5df0625 | 2009-11-14 20:09:13 +0000 | [diff] [blame] | 1294 | for (size_t i = 0, e = JumpTables.size(); i != e; ++i) |
| 1295 | ReplaceMBBInJumpTable(i, Old, New); |
| 1296 | return MadeChange; |
| 1297 | } |
| 1298 | |
Victor Huang | 347c461 | 2020-11-16 10:33:06 -0600 | [diff] [blame] | 1299 | /// If MBB is present in any jump tables, remove it. |
| 1300 | bool MachineJumpTableInfo::RemoveMBBFromJumpTables(MachineBasicBlock *MBB) { |
| 1301 | bool MadeChange = false; |
| 1302 | for (MachineJumpTableEntry &JTE : JumpTables) { |
| 1303 | auto removeBeginItr = std::remove(JTE.MBBs.begin(), JTE.MBBs.end(), MBB); |
| 1304 | MadeChange |= (removeBeginItr != JTE.MBBs.end()); |
| 1305 | JTE.MBBs.erase(removeBeginItr, JTE.MBBs.end()); |
| 1306 | } |
| 1307 | return MadeChange; |
| 1308 | } |
| 1309 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 1310 | /// If Old is a target of the jump tables, update the jump table to branch to |
| 1311 | /// New instead. |
Chris Lattner | 80a6849 | 2010-01-26 05:58:28 +0000 | [diff] [blame] | 1312 | bool MachineJumpTableInfo::ReplaceMBBInJumpTable(unsigned Idx, |
| 1313 | MachineBasicBlock *Old, |
| 1314 | MachineBasicBlock *New) { |
Jim Grosbach | 5df0625 | 2009-11-14 20:09:13 +0000 | [diff] [blame] | 1315 | assert(Old != New && "Not making a change?"); |
| 1316 | bool MadeChange = false; |
| 1317 | MachineJumpTableEntry &JTE = JumpTables[Idx]; |
Kazu Hirata | 74d9b88 | 2021-11-22 20:33:27 -0800 | [diff] [blame] | 1318 | for (MachineBasicBlock *&MBB : JTE.MBBs) |
| 1319 | if (MBB == Old) { |
| 1320 | MBB = New; |
Jim Grosbach | 5df0625 | 2009-11-14 20:09:13 +0000 | [diff] [blame] | 1321 | MadeChange = true; |
| 1322 | } |
Dan Gohman | 557b391 | 2009-04-15 01:18:49 +0000 | [diff] [blame] | 1323 | return MadeChange; |
| 1324 | } |
Nate Begeman | 83e5f08 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1325 | |
Chris Lattner | b1d55db | 2009-08-23 01:12:47 +0000 | [diff] [blame] | 1326 | void MachineJumpTableInfo::print(raw_ostream &OS) const { |
Dan Gohman | 89871b6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 1327 | if (JumpTables.empty()) return; |
| 1328 | |
| 1329 | OS << "Jump Tables:\n"; |
| 1330 | |
Nate Begeman | 83e5f08 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1331 | for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) { |
Evandro Menezes | 5a515cd | 2019-06-26 15:11:31 +0000 | [diff] [blame] | 1332 | OS << printJumpTableEntryReference(i) << ':'; |
Kazu Hirata | 74d9b88 | 2021-11-22 20:33:27 -0800 | [diff] [blame] | 1333 | for (const MachineBasicBlock *MBB : JumpTables[i].MBBs) |
| 1334 | OS << ' ' << printMBBReference(*MBB); |
Evandro Menezes | 5a515cd | 2019-06-26 15:11:31 +0000 | [diff] [blame] | 1335 | if (i != e) |
| 1336 | OS << '\n'; |
Nate Begeman | 83e5f08 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1337 | } |
Dan Gohman | 89871b6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 1338 | |
| 1339 | OS << '\n'; |
Nate Begeman | 83e5f08 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1340 | } |
| 1341 | |
Aaron Ballman | 7fced3f | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 1342 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Yaron Keren | 33afa9a | 2016-01-29 20:50:44 +0000 | [diff] [blame] | 1343 | LLVM_DUMP_METHOD void MachineJumpTableInfo::dump() const { print(dbgs()); } |
Manman Ren | 4f061be | 2012-09-06 19:06:06 +0000 | [diff] [blame] | 1344 | #endif |
Nate Begeman | 83e5f08 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1345 | |
Francis Visoiu Mistrih | 45acd39 | 2017-12-13 10:30:59 +0000 | [diff] [blame] | 1346 | Printable llvm::printJumpTableEntryReference(unsigned Idx) { |
| 1347 | return Printable([Idx](raw_ostream &OS) { OS << "%jump-table." << Idx; }); |
| 1348 | } |
| 1349 | |
Nate Begeman | 83e5f08 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1350 | //===----------------------------------------------------------------------===// |
Chris Lattner | e151161 | 2003-01-13 00:23:03 +0000 | [diff] [blame] | 1351 | // MachineConstantPool implementation |
| 1352 | //===----------------------------------------------------------------------===// |
| 1353 | |
Eugene Zelenko | 9375b78 | 2017-10-10 22:33:29 +0000 | [diff] [blame] | 1354 | void MachineConstantPoolValue::anchor() {} |
David Blaikie | cd738cc | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 1355 | |
QingShan Zhang | 778a900 | 2021-01-05 03:22:45 +0000 | [diff] [blame] | 1356 | unsigned MachineConstantPoolValue::getSizeInBytes(const DataLayout &DL) const { |
| 1357 | return DL.getTypeAllocSize(Ty); |
| 1358 | } |
| 1359 | |
| 1360 | unsigned MachineConstantPoolEntry::getSizeInBytes(const DataLayout &DL) const { |
Evan Cheng | 1c50043 | 2006-09-14 05:50:57 +0000 | [diff] [blame] | 1361 | if (isMachineConstantPoolEntry()) |
QingShan Zhang | 778a900 | 2021-01-05 03:22:45 +0000 | [diff] [blame] | 1362 | return Val.MachineCPVal->getSizeInBytes(DL); |
| 1363 | return DL.getTypeAllocSize(Val.ConstVal->getType()); |
Evan Cheng | 1c50043 | 2006-09-14 05:50:57 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
Rafael Espindola | 1a213e4 | 2015-11-17 00:51:23 +0000 | [diff] [blame] | 1366 | bool MachineConstantPoolEntry::needsRelocation() const { |
Chris Lattner | a0453a9 | 2009-07-21 23:34:23 +0000 | [diff] [blame] | 1367 | if (isMachineConstantPoolEntry()) |
Rafael Espindola | 1a213e4 | 2015-11-17 00:51:23 +0000 | [diff] [blame] | 1368 | return true; |
Leonard Chan | 1719ae6 | 2021-02-10 09:59:36 -0800 | [diff] [blame] | 1369 | return Val.ConstVal->needsDynamicRelocation(); |
Chris Lattner | a0453a9 | 2009-07-21 23:34:23 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
David Majnemer | b0a4e78 | 2014-07-14 22:06:29 +0000 | [diff] [blame] | 1372 | SectionKind |
| 1373 | MachineConstantPoolEntry::getSectionKind(const DataLayout *DL) const { |
Rafael Espindola | 1a213e4 | 2015-11-17 00:51:23 +0000 | [diff] [blame] | 1374 | if (needsRelocation()) |
| 1375 | return SectionKind::getReadOnlyWithRel(); |
QingShan Zhang | 778a900 | 2021-01-05 03:22:45 +0000 | [diff] [blame] | 1376 | switch (getSizeInBytes(*DL)) { |
Rafael Espindola | 1a213e4 | 2015-11-17 00:51:23 +0000 | [diff] [blame] | 1377 | case 4: |
| 1378 | return SectionKind::getMergeableConst4(); |
| 1379 | case 8: |
| 1380 | return SectionKind::getMergeableConst8(); |
| 1381 | case 16: |
| 1382 | return SectionKind::getMergeableConst16(); |
David Majnemer | 125c7bf | 2016-02-22 22:23:11 +0000 | [diff] [blame] | 1383 | case 32: |
| 1384 | return SectionKind::getMergeableConst32(); |
David Majnemer | b0a4e78 | 2014-07-14 22:06:29 +0000 | [diff] [blame] | 1385 | default: |
Rafael Espindola | 1a213e4 | 2015-11-17 00:51:23 +0000 | [diff] [blame] | 1386 | return SectionKind::getReadOnly(); |
David Majnemer | b0a4e78 | 2014-07-14 22:06:29 +0000 | [diff] [blame] | 1387 | } |
David Majnemer | b0a4e78 | 2014-07-14 22:06:29 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
Evan Cheng | bb4b58c | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1390 | MachineConstantPool::~MachineConstantPool() { |
James Molloy | 5dbdef8 | 2016-09-26 07:26:24 +0000 | [diff] [blame] | 1391 | // A constant may be a member of both Constants and MachineCPVsSharingEntries, |
| 1392 | // so keep track of which we've deleted to avoid double deletions. |
| 1393 | DenseSet<MachineConstantPoolValue*> Deleted; |
Kazu Hirata | 655998b | 2021-12-04 08:48:04 -0800 | [diff] [blame] | 1394 | for (const MachineConstantPoolEntry &C : Constants) |
| 1395 | if (C.isMachineConstantPoolEntry()) { |
| 1396 | Deleted.insert(C.Val.MachineCPVal); |
| 1397 | delete C.Val.MachineCPVal; |
James Molloy | 5dbdef8 | 2016-09-26 07:26:24 +0000 | [diff] [blame] | 1398 | } |
Kazu Hirata | 44969dc | 2021-02-15 14:46:10 -0800 | [diff] [blame] | 1399 | for (MachineConstantPoolValue *CPV : MachineCPVsSharingEntries) { |
| 1400 | if (Deleted.count(CPV) == 0) |
| 1401 | delete CPV; |
James Molloy | 5dbdef8 | 2016-09-26 07:26:24 +0000 | [diff] [blame] | 1402 | } |
Evan Cheng | bb4b58c | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1403 | } |
| 1404 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 1405 | /// Test whether the given two constants can be allocated the same constant pool |
Simon Pilgrim | 96e646d | 2023-06-13 10:15:02 +0100 | [diff] [blame] | 1406 | /// entry referenced by \param A. |
Dan Gohman | 90cad46 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1407 | static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B, |
Mehdi Amini | c0a24f6 | 2015-07-07 18:20:57 +0000 | [diff] [blame] | 1408 | const DataLayout &DL) { |
Dan Gohman | 8d4ffb3 | 2009-10-28 01:12:16 +0000 | [diff] [blame] | 1409 | // Handle the trivial case quickly. |
| 1410 | if (A == B) return true; |
| 1411 | |
| 1412 | // If they have the same type but weren't the same constant, quickly |
| 1413 | // reject them. |
| 1414 | if (A->getType() == B->getType()) return false; |
| 1415 | |
Chris Lattner | 5c0ff07 | 2012-01-27 01:46:00 +0000 | [diff] [blame] | 1416 | // We can't handle structs or arrays. |
| 1417 | if (isa<StructType>(A->getType()) || isa<ArrayType>(A->getType()) || |
| 1418 | isa<StructType>(B->getType()) || isa<ArrayType>(B->getType())) |
| 1419 | return false; |
NAKAMURA Takumi | e82ebbb | 2014-06-25 12:40:56 +0000 | [diff] [blame] | 1420 | |
Dan Gohman | 8d4ffb3 | 2009-10-28 01:12:16 +0000 | [diff] [blame] | 1421 | // For now, only support constants with the same size. |
Mehdi Amini | c0a24f6 | 2015-07-07 18:20:57 +0000 | [diff] [blame] | 1422 | uint64_t StoreSize = DL.getTypeStoreSize(A->getType()); |
| 1423 | if (StoreSize != DL.getTypeStoreSize(B->getType()) || StoreSize > 128) |
Dan Gohman | 8d4ffb3 | 2009-10-28 01:12:16 +0000 | [diff] [blame] | 1424 | return false; |
| 1425 | |
Simon Pilgrim | 96e646d | 2023-06-13 10:15:02 +0100 | [diff] [blame] | 1426 | bool ContainsUndefOrPoisonA = A->containsUndefOrPoisonElement(); |
| 1427 | |
Chris Lattner | 5c0ff07 | 2012-01-27 01:46:00 +0000 | [diff] [blame] | 1428 | Type *IntTy = IntegerType::get(A->getContext(), StoreSize*8); |
Dan Gohman | 8d4ffb3 | 2009-10-28 01:12:16 +0000 | [diff] [blame] | 1429 | |
Chris Lattner | 5c0ff07 | 2012-01-27 01:46:00 +0000 | [diff] [blame] | 1430 | // Try constant folding a bitcast of both instructions to an integer. If we |
| 1431 | // get two identical ConstantInt's, then we are good to share them. We use |
| 1432 | // the constant folding APIs to do this so that we get the benefit of |
Micah Villmow | fda694e | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 1433 | // DataLayout. |
Chris Lattner | 5c0ff07 | 2012-01-27 01:46:00 +0000 | [diff] [blame] | 1434 | if (isa<PointerType>(A->getType())) |
Manuel Jacob | 56d0313 | 2016-01-21 06:31:08 +0000 | [diff] [blame] | 1435 | A = ConstantFoldCastOperand(Instruction::PtrToInt, |
| 1436 | const_cast<Constant *>(A), IntTy, DL); |
Chris Lattner | 5c0ff07 | 2012-01-27 01:46:00 +0000 | [diff] [blame] | 1437 | else if (A->getType() != IntTy) |
Manuel Jacob | 56d0313 | 2016-01-21 06:31:08 +0000 | [diff] [blame] | 1438 | A = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(A), |
| 1439 | IntTy, DL); |
Chris Lattner | 5c0ff07 | 2012-01-27 01:46:00 +0000 | [diff] [blame] | 1440 | if (isa<PointerType>(B->getType())) |
Manuel Jacob | 56d0313 | 2016-01-21 06:31:08 +0000 | [diff] [blame] | 1441 | B = ConstantFoldCastOperand(Instruction::PtrToInt, |
| 1442 | const_cast<Constant *>(B), IntTy, DL); |
Chris Lattner | 5c0ff07 | 2012-01-27 01:46:00 +0000 | [diff] [blame] | 1443 | else if (B->getType() != IntTy) |
Manuel Jacob | 56d0313 | 2016-01-21 06:31:08 +0000 | [diff] [blame] | 1444 | B = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(B), |
| 1445 | IntTy, DL); |
Chad Rosier | be02a0a | 2012-06-19 23:37:57 +0000 | [diff] [blame] | 1446 | |
Simon Pilgrim | 96e646d | 2023-06-13 10:15:02 +0100 | [diff] [blame] | 1447 | if (A != B) |
| 1448 | return false; |
| 1449 | |
| 1450 | // Constants only safely match if A doesn't contain undef/poison. |
| 1451 | // As we'll be reusing A, it doesn't matter if B contain undef/poison. |
| 1452 | // TODO: Handle cases where A and B have the same undef/poison elements. |
| 1453 | // TODO: Merge A and B with mismatching undef/poison elements. |
| 1454 | return !ContainsUndefOrPoisonA; |
Dan Gohman | 8d4ffb3 | 2009-10-28 01:12:16 +0000 | [diff] [blame] | 1455 | } |
| 1456 | |
Sanjay Patel | a3bab49 | 2015-06-13 15:32:45 +0000 | [diff] [blame] | 1457 | /// Create a new entry in the constant pool or return an existing one. |
| 1458 | /// User must specify the log2 of the minimum required alignment for the object. |
NAKAMURA Takumi | e82ebbb | 2014-06-25 12:40:56 +0000 | [diff] [blame] | 1459 | unsigned MachineConstantPool::getConstantPoolIndex(const Constant *C, |
Craig Topper | 3b2c995 | 2020-05-12 09:43:24 -0700 | [diff] [blame] | 1460 | Align Alignment) { |
Chris Lattner | ee31d0d | 2006-02-09 04:46:04 +0000 | [diff] [blame] | 1461 | if (Alignment > PoolAlignment) PoolAlignment = Alignment; |
Dan Gohman | 8d4ffb3 | 2009-10-28 01:12:16 +0000 | [diff] [blame] | 1462 | |
Chris Lattner | ee31d0d | 2006-02-09 04:46:04 +0000 | [diff] [blame] | 1463 | // Check to see if we already have this constant. |
| 1464 | // |
| 1465 | // FIXME, this could be made much more efficient for large constant pools. |
Chris Lattner | ee31d0d | 2006-02-09 04:46:04 +0000 | [diff] [blame] | 1466 | for (unsigned i = 0, e = Constants.size(); i != e; ++i) |
Dan Gohman | 8d4ffb3 | 2009-10-28 01:12:16 +0000 | [diff] [blame] | 1467 | if (!Constants[i].isMachineConstantPoolEntry() && |
Mehdi Amini | c0a24f6 | 2015-07-07 18:20:57 +0000 | [diff] [blame] | 1468 | CanShareConstantPoolEntry(Constants[i].Val.ConstVal, C, DL)) { |
Craig Topper | 3b2c995 | 2020-05-12 09:43:24 -0700 | [diff] [blame] | 1469 | if (Constants[i].getAlign() < Alignment) |
Dan Gohman | 8d4ffb3 | 2009-10-28 01:12:16 +0000 | [diff] [blame] | 1470 | Constants[i].Alignment = Alignment; |
Chris Lattner | ee31d0d | 2006-02-09 04:46:04 +0000 | [diff] [blame] | 1471 | return i; |
Dan Gohman | 8d4ffb3 | 2009-10-28 01:12:16 +0000 | [diff] [blame] | 1472 | } |
Chad Rosier | be02a0a | 2012-06-19 23:37:57 +0000 | [diff] [blame] | 1473 | |
Evan Cheng | 24d890f | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1474 | Constants.push_back(MachineConstantPoolEntry(C, Alignment)); |
Chris Lattner | ee31d0d | 2006-02-09 04:46:04 +0000 | [diff] [blame] | 1475 | return Constants.size()-1; |
| 1476 | } |
| 1477 | |
Evan Cheng | bb4b58c | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1478 | unsigned MachineConstantPool::getConstantPoolIndex(MachineConstantPoolValue *V, |
Craig Topper | 3b2c995 | 2020-05-12 09:43:24 -0700 | [diff] [blame] | 1479 | Align Alignment) { |
Evan Cheng | bb4b58c | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1480 | if (Alignment > PoolAlignment) PoolAlignment = Alignment; |
Chad Rosier | be02a0a | 2012-06-19 23:37:57 +0000 | [diff] [blame] | 1481 | |
Evan Cheng | bb4b58c | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1482 | // Check to see if we already have this constant. |
| 1483 | // |
| 1484 | // FIXME, this could be made much more efficient for large constant pools. |
Evan Cheng | bb4b58c | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1485 | int Idx = V->getExistingMachineCPValue(this, Alignment); |
Cameron Zwarich | 9d2cc5d | 2011-02-22 08:54:30 +0000 | [diff] [blame] | 1486 | if (Idx != -1) { |
| 1487 | MachineCPVsSharingEntries.insert(V); |
Evan Cheng | bb4b58c | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1488 | return (unsigned)Idx; |
Cameron Zwarich | 9d2cc5d | 2011-02-22 08:54:30 +0000 | [diff] [blame] | 1489 | } |
Evan Cheng | 24d890f | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1490 | |
| 1491 | Constants.push_back(MachineConstantPoolEntry(V, Alignment)); |
Evan Cheng | bb4b58c | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1492 | return Constants.size()-1; |
| 1493 | } |
| 1494 | |
Chris Lattner | fd02f77 | 2008-08-23 22:53:13 +0000 | [diff] [blame] | 1495 | void MachineConstantPool::print(raw_ostream &OS) const { |
Dan Gohman | 89871b6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 1496 | if (Constants.empty()) return; |
| 1497 | |
| 1498 | OS << "Constant Pool:\n"; |
Evan Cheng | 1057050 | 2006-01-31 22:23:14 +0000 | [diff] [blame] | 1499 | for (unsigned i = 0, e = Constants.size(); i != e; ++i) { |
Dan Gohman | 89871b6 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 1500 | OS << " cp#" << i << ": "; |
Evan Cheng | bb4b58c | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1501 | if (Constants[i].isMachineConstantPoolEntry()) |
| 1502 | Constants[i].Val.MachineCPVal->print(OS); |
| 1503 | else |
Chandler Carruth | e694828 | 2014-01-09 02:29:41 +0000 | [diff] [blame] | 1504 | Constants[i].Val.ConstVal->printAsOperand(OS, /*PrintType=*/false); |
Craig Topper | 3b2c995 | 2020-05-12 09:43:24 -0700 | [diff] [blame] | 1505 | OS << ", align=" << Constants[i].getAlign().value(); |
Evan Cheng | 1057050 | 2006-01-31 22:23:14 +0000 | [diff] [blame] | 1506 | OS << "\n"; |
| 1507 | } |
Chris Lattner | e151161 | 2003-01-13 00:23:03 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
Han Shen | c5e8527 | 2023-06-28 22:18:53 -0700 | [diff] [blame] | 1510 | //===----------------------------------------------------------------------===// |
| 1511 | // Template specialization for MachineFunction implementation of |
| 1512 | // ProfileSummaryInfo::getEntryCount(). |
| 1513 | //===----------------------------------------------------------------------===// |
| 1514 | template <> |
| 1515 | std::optional<Function::ProfileCount> |
| 1516 | ProfileSummaryInfo::getEntryCount<llvm::MachineFunction>( |
| 1517 | const llvm::MachineFunction *F) const { |
| 1518 | return F->getFunction().getEntryCount(); |
| 1519 | } |
| 1520 | |
Aaron Ballman | 7fced3f | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 1521 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Yaron Keren | 33afa9a | 2016-01-29 20:50:44 +0000 | [diff] [blame] | 1522 | LLVM_DUMP_METHOD void MachineConstantPool::dump() const { print(dbgs()); } |
Manman Ren | 4f061be | 2012-09-06 19:06:06 +0000 | [diff] [blame] | 1523 | #endif |