blob: 6ef8de88f8b117484dcaf0d6fd2df4864c4cd7cc [file] [log] [blame]
Jim Laskey6da18642007-01-26 21:38:26 +00001//===-- llvm/CodeGen/MachineModuleInfo.cpp ----------------------*- C++ -*-===//
Jim Laskey6af56812006-01-04 13:36:38 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jim Laskey6af56812006-01-04 13:36:38 +00007//
8//===----------------------------------------------------------------------===//
Jim Laskey6af56812006-01-04 13:36:38 +00009
Chandler Carruthe3e43d92017-06-06 11:49:48 +000010#include "llvm/CodeGen/MachineModuleInfo.h"
Eugene Zelenko1d081e62017-05-31 01:10:10 +000011#include "llvm/ADT/ArrayRef.h"
12#include "llvm/ADT/DenseMap.h"
Ahmed Bougachaf522e202016-11-16 22:24:56 +000013#include "llvm/ADT/PostOrderIterator.h"
Eugene Zelenko1d081e62017-05-31 01:10:10 +000014#include "llvm/ADT/StringRef.h"
Reid Kleckner595419d2015-11-17 21:10:25 +000015#include "llvm/ADT/TinyPtrVector.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000016#include "llvm/CodeGen/MachineFunction.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000017#include "llvm/CodeGen/Passes.h"
Eugene Zelenko1d081e62017-05-31 01:10:10 +000018#include "llvm/IR/BasicBlock.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000019#include "llvm/IR/DerivedTypes.h"
Ahmed Bougachaf522e202016-11-16 22:24:56 +000020#include "llvm/IR/Instructions.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000021#include "llvm/IR/Module.h"
Eugene Zelenko1d081e62017-05-31 01:10:10 +000022#include "llvm/IR/Value.h"
23#include "llvm/IR/ValueHandle.h"
24#include "llvm/MC/MCContext.h"
Chris Lattner16112732010-03-14 01:41:15 +000025#include "llvm/MC/MCSymbol.h"
Eugene Zelenko1d081e62017-05-31 01:10:10 +000026#include "llvm/Pass.h"
27#include "llvm/Support/Casting.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000028#include "llvm/Support/ErrorHandling.h"
David Blaikiefe42bd52018-03-23 23:58:19 +000029#include "llvm/Target/TargetLoweringObjectFile.h"
Matthias Braun43f89c52016-08-24 00:42:05 +000030#include "llvm/Target/TargetMachine.h"
Eugene Zelenko1d081e62017-05-31 01:10:10 +000031#include <algorithm>
32#include <cassert>
33#include <memory>
34#include <utility>
35#include <vector>
36
Jim Laskey6af56812006-01-04 13:36:38 +000037using namespace llvm;
Jim Laskey9c4447a2006-03-01 20:39:36 +000038using namespace llvm::dwarf;
Jim Laskey6af56812006-01-04 13:36:38 +000039
Micah Villmow3574eca2012-10-08 16:38:25 +000040// Handle the Pass registration stuff necessary to use DataLayout's.
Francis Visoiu Mistrihae1c8532017-05-18 17:21:13 +000041INITIALIZE_PASS(MachineModuleInfo, "machinemoduleinfo",
42 "Machine Module Information", false, false)
Devang Patel19974732007-05-03 01:11:54 +000043char MachineModuleInfo::ID = 0;
Jim Laskey063e7652006-01-17 17:31:53 +000044
Chris Lattnera70e2e32009-09-15 22:44:26 +000045// Out of line virtual method.
Eugene Zelenko1d081e62017-05-31 01:10:10 +000046MachineModuleInfoImpl::~MachineModuleInfoImpl() = default;
Chris Lattnera70e2e32009-09-15 22:44:26 +000047
Chris Lattner0220ba72010-03-15 19:09:43 +000048namespace llvm {
Eugene Zelenko1d081e62017-05-31 01:10:10 +000049
David Blaikiec4423f02015-08-03 22:30:24 +000050class MMIAddrLabelMapCallbackPtr final : CallbackVH {
Eugene Zelenko1d081e62017-05-31 01:10:10 +000051 MMIAddrLabelMap *Map = nullptr;
52
Chris Lattner0220ba72010-03-15 19:09:43 +000053public:
Eugene Zelenko1d081e62017-05-31 01:10:10 +000054 MMIAddrLabelMapCallbackPtr() = default;
55 MMIAddrLabelMapCallbackPtr(Value *V) : CallbackVH(V) {}
Michael J. Spencere70c5262010-10-16 08:25:21 +000056
Chris Lattnerea16ea52010-03-22 23:15:57 +000057 void setPtr(BasicBlock *BB) {
58 ValueHandleBase::operator=(BB);
59 }
Michael J. Spencere70c5262010-10-16 08:25:21 +000060
Chris Lattner0220ba72010-03-15 19:09:43 +000061 void setMap(MMIAddrLabelMap *map) { Map = map; }
Michael J. Spencere70c5262010-10-16 08:25:21 +000062
Craig Topper9f998de2014-03-07 09:26:03 +000063 void deleted() override;
64 void allUsesReplacedWith(Value *V2) override;
Chris Lattner0220ba72010-03-15 19:09:43 +000065};
Michael J. Spencere70c5262010-10-16 08:25:21 +000066
Chris Lattner0220ba72010-03-15 19:09:43 +000067class MMIAddrLabelMap {
68 MCContext &Context;
69 struct AddrLabelSymEntry {
Ahmed Bougacha8d35b782016-11-16 22:24:53 +000070 /// The symbols for the label.
Benjamin Kramer17d72152015-06-29 20:21:55 +000071 TinyPtrVector<MCSymbol *> Symbols;
Michael J. Spencere70c5262010-10-16 08:25:21 +000072
Chris Lattner9cc0da92010-03-15 20:39:00 +000073 Function *Fn; // The containing function of the BasicBlock.
74 unsigned Index; // The index in BBCallbacks for the BasicBlock.
Chris Lattner0220ba72010-03-15 19:09:43 +000075 };
Michael J. Spencere70c5262010-10-16 08:25:21 +000076
Chris Lattner0220ba72010-03-15 19:09:43 +000077 DenseMap<AssertingVH<BasicBlock>, AddrLabelSymEntry> AddrLabelSymbols;
Michael J. Spencere70c5262010-10-16 08:25:21 +000078
Ahmed Bougacha8d35b782016-11-16 22:24:53 +000079 /// Callbacks for the BasicBlock's that we have entries for. We use this so
80 /// we get notified if a block is deleted or RAUWd.
Chris Lattner0220ba72010-03-15 19:09:43 +000081 std::vector<MMIAddrLabelMapCallbackPtr> BBCallbacks;
Chris Lattner9cc0da92010-03-15 20:39:00 +000082
Ahmed Bougacha8d35b782016-11-16 22:24:53 +000083 /// This is a per-function list of symbols whose corresponding BasicBlock got
84 /// deleted. These symbols need to be emitted at some point in the file, so
85 /// AsmPrinter emits them after the function body.
Eugene Zelenko1d081e62017-05-31 01:10:10 +000086 DenseMap<AssertingVH<Function>, std::vector<MCSymbol*>>
Chris Lattner9cc0da92010-03-15 20:39:00 +000087 DeletedAddrLabelsNeedingEmission;
Michael J. Spencere70c5262010-10-16 08:25:21 +000088
Eugene Zelenko1d081e62017-05-31 01:10:10 +000089public:
Chris Lattner0220ba72010-03-15 19:09:43 +000090 MMIAddrLabelMap(MCContext &context) : Context(context) {}
Eugene Zelenko1d081e62017-05-31 01:10:10 +000091
Chris Lattner9cc0da92010-03-15 20:39:00 +000092 ~MMIAddrLabelMap() {
93 assert(DeletedAddrLabelsNeedingEmission.empty() &&
94 "Some labels for deleted blocks never got emitted");
95 }
Michael J. Spencere70c5262010-10-16 08:25:21 +000096
Benjamin Kramer17d72152015-06-29 20:21:55 +000097 ArrayRef<MCSymbol *> getAddrLabelSymbolToEmit(BasicBlock *BB);
Chris Lattner999aee22010-03-16 00:29:39 +000098
Michael J. Spencere70c5262010-10-16 08:25:21 +000099 void takeDeletedSymbolsForFunction(Function *F,
Chris Lattner9cc0da92010-03-15 20:39:00 +0000100 std::vector<MCSymbol*> &Result);
101
Chris Lattner0220ba72010-03-15 19:09:43 +0000102 void UpdateForDeletedBlock(BasicBlock *BB);
103 void UpdateForRAUWBlock(BasicBlock *Old, BasicBlock *New);
104};
Eugene Zelenko1d081e62017-05-31 01:10:10 +0000105
106} // end namespace llvm
Chris Lattner0220ba72010-03-15 19:09:43 +0000107
Benjamin Kramer17d72152015-06-29 20:21:55 +0000108ArrayRef<MCSymbol *> MMIAddrLabelMap::getAddrLabelSymbolToEmit(BasicBlock *BB) {
Chris Lattner0220ba72010-03-15 19:09:43 +0000109 assert(BB->hasAddressTaken() &&
110 "Shouldn't get label for block without address taken");
111 AddrLabelSymEntry &Entry = AddrLabelSymbols[BB];
Michael J. Spencere70c5262010-10-16 08:25:21 +0000112
Chris Lattner0220ba72010-03-15 19:09:43 +0000113 // If we already had an entry for this block, just return it.
Benjamin Kramer17d72152015-06-29 20:21:55 +0000114 if (!Entry.Symbols.empty()) {
Chris Lattner9cc0da92010-03-15 20:39:00 +0000115 assert(BB->getParent() == Entry.Fn && "Parent changed");
Benjamin Kramer17d72152015-06-29 20:21:55 +0000116 return Entry.Symbols;
Chris Lattner9cc0da92010-03-15 20:39:00 +0000117 }
Michael J. Spencere70c5262010-10-16 08:25:21 +0000118
Chris Lattner0220ba72010-03-15 19:09:43 +0000119 // Otherwise, this is a new entry, create a new symbol for it and add an
120 // entry to BBCallbacks so we can be notified if the BB is deleted or RAUWd.
Benjamin Kramer9589ff82015-05-29 19:43:39 +0000121 BBCallbacks.emplace_back(BB);
Chris Lattner0220ba72010-03-15 19:09:43 +0000122 BBCallbacks.back().setMap(this);
Benjamin Kramer17d72152015-06-29 20:21:55 +0000123 Entry.Index = BBCallbacks.size() - 1;
Chris Lattner9cc0da92010-03-15 20:39:00 +0000124 Entry.Fn = BB->getParent();
Benjamin Kramer17d72152015-06-29 20:21:55 +0000125 Entry.Symbols.push_back(Context.createTempSymbol());
126 return Entry.Symbols;
Chris Lattner0220ba72010-03-15 19:09:43 +0000127}
128
Ahmed Bougacha8d35b782016-11-16 22:24:53 +0000129/// If we have any deleted symbols for F, return them.
Chris Lattner9cc0da92010-03-15 20:39:00 +0000130void MMIAddrLabelMap::
131takeDeletedSymbolsForFunction(Function *F, std::vector<MCSymbol*> &Result) {
Eugene Zelenko1d081e62017-05-31 01:10:10 +0000132 DenseMap<AssertingVH<Function>, std::vector<MCSymbol*>>::iterator I =
Chris Lattner9cc0da92010-03-15 20:39:00 +0000133 DeletedAddrLabelsNeedingEmission.find(F);
134
135 // If there are no entries for the function, just return.
136 if (I == DeletedAddrLabelsNeedingEmission.end()) return;
Michael J. Spencere70c5262010-10-16 08:25:21 +0000137
Chris Lattner9cc0da92010-03-15 20:39:00 +0000138 // Otherwise, take the list.
139 std::swap(Result, I->second);
140 DeletedAddrLabelsNeedingEmission.erase(I);
141}
142
Chris Lattner0220ba72010-03-15 19:09:43 +0000143void MMIAddrLabelMap::UpdateForDeletedBlock(BasicBlock *BB) {
144 // If the block got deleted, there is no need for the symbol. If the symbol
145 // was already emitted, we can just forget about it, otherwise we need to
146 // queue it up for later emission when the function is output.
Benjamin Kramer17d72152015-06-29 20:21:55 +0000147 AddrLabelSymEntry Entry = std::move(AddrLabelSymbols[BB]);
Chris Lattner0220ba72010-03-15 19:09:43 +0000148 AddrLabelSymbols.erase(BB);
Benjamin Kramer17d72152015-06-29 20:21:55 +0000149 assert(!Entry.Symbols.empty() && "Didn't have a symbol, why a callback?");
Craig Topper4ba84432014-04-14 00:51:57 +0000150 BBCallbacks[Entry.Index] = nullptr; // Clear the callback.
Chris Lattner0220ba72010-03-15 19:09:43 +0000151
Craig Topper4ba84432014-04-14 00:51:57 +0000152 assert((BB->getParent() == nullptr || BB->getParent() == Entry.Fn) &&
Chris Lattner9cc0da92010-03-15 20:39:00 +0000153 "Block/parent mismatch");
Chris Lattner999aee22010-03-16 00:29:39 +0000154
Benjamin Kramer17d72152015-06-29 20:21:55 +0000155 for (MCSymbol *Sym : Entry.Symbols) {
Chris Lattner999aee22010-03-16 00:29:39 +0000156 if (Sym->isDefined())
157 return;
Michael J. Spencere70c5262010-10-16 08:25:21 +0000158
Chris Lattner999aee22010-03-16 00:29:39 +0000159 // If the block is not yet defined, we need to emit it at the end of the
160 // function. Add the symbol to the DeletedAddrLabelsNeedingEmission list
161 // for the containing Function. Since the block is being deleted, its
162 // parent may already be removed, we have to get the function from 'Entry'.
163 DeletedAddrLabelsNeedingEmission[Entry.Fn].push_back(Sym);
Chris Lattner999aee22010-03-16 00:29:39 +0000164 }
Chris Lattner0220ba72010-03-15 19:09:43 +0000165}
166
167void MMIAddrLabelMap::UpdateForRAUWBlock(BasicBlock *Old, BasicBlock *New) {
168 // Get the entry for the RAUW'd block and remove it from our map.
Benjamin Kramer17d72152015-06-29 20:21:55 +0000169 AddrLabelSymEntry OldEntry = std::move(AddrLabelSymbols[Old]);
Chris Lattner0220ba72010-03-15 19:09:43 +0000170 AddrLabelSymbols.erase(Old);
Benjamin Kramer17d72152015-06-29 20:21:55 +0000171 assert(!OldEntry.Symbols.empty() && "Didn't have a symbol, why a callback?");
Chris Lattner999aee22010-03-16 00:29:39 +0000172
173 AddrLabelSymEntry &NewEntry = AddrLabelSymbols[New];
174
Chris Lattner0220ba72010-03-15 19:09:43 +0000175 // If New is not address taken, just move our symbol over to it.
Benjamin Kramer17d72152015-06-29 20:21:55 +0000176 if (NewEntry.Symbols.empty()) {
Chris Lattnerea16ea52010-03-22 23:15:57 +0000177 BBCallbacks[OldEntry.Index].setPtr(New); // Update the callback.
Benjamin Kramer17d72152015-06-29 20:21:55 +0000178 NewEntry = std::move(OldEntry); // Set New's entry.
Chris Lattner999aee22010-03-16 00:29:39 +0000179 return;
Chris Lattner0220ba72010-03-15 19:09:43 +0000180 }
Chris Lattner999aee22010-03-16 00:29:39 +0000181
Craig Topper4ba84432014-04-14 00:51:57 +0000182 BBCallbacks[OldEntry.Index] = nullptr; // Update the callback.
Chris Lattner999aee22010-03-16 00:29:39 +0000183
Benjamin Kramer17d72152015-06-29 20:21:55 +0000184 // Otherwise, we need to add the old symbols to the new block's set.
185 NewEntry.Symbols.insert(NewEntry.Symbols.end(), OldEntry.Symbols.begin(),
186 OldEntry.Symbols.end());
Chris Lattner0220ba72010-03-15 19:09:43 +0000187}
188
Chris Lattner0220ba72010-03-15 19:09:43 +0000189void MMIAddrLabelMapCallbackPtr::deleted() {
190 Map->UpdateForDeletedBlock(cast<BasicBlock>(getValPtr()));
191}
192
193void MMIAddrLabelMapCallbackPtr::allUsesReplacedWith(Value *V2) {
194 Map->UpdateForRAUWBlock(cast<BasicBlock>(getValPtr()), cast<BasicBlock>(V2));
195}
196
Matthias Braun51c2c7a2018-11-05 23:49:13 +0000197MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM)
Matthias Braunfa5c5c72016-08-24 01:52:46 +0000198 : ImmutablePass(ID), TM(*TM),
199 Context(TM->getMCAsmInfo(), TM->getMCRegisterInfo(),
200 TM->getObjFileLowering(), nullptr, false) {
Owen Anderson081c34b2010-10-19 17:21:58 +0000201 initializeMachineModuleInfoPass(*PassRegistry::getPassRegistry());
Anton Korobeynikov8c7c1732007-05-13 15:42:26 +0000202}
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000203
Eugene Zelenko1d081e62017-05-31 01:10:10 +0000204MachineModuleInfo::~MachineModuleInfo() = default;
Michael J. Spencere70c5262010-10-16 08:25:21 +0000205
Pedro Artigasd1abec32012-12-05 17:12:22 +0000206bool MachineModuleInfo::doInitialization(Module &M) {
Craig Topper4ba84432014-04-14 00:51:57 +0000207 ObjFileMMI = nullptr;
Pedro Artigasd1abec32012-12-05 17:12:22 +0000208 CurCallSite = 0;
Matthias Braun08b668a2018-10-31 17:18:41 +0000209 UsesVAFloatArgument = UsesMorestackAddr = false;
Than McIntosh3962d562017-09-27 19:34:00 +0000210 HasSplitStack = HasNosplitStack = false;
Craig Topper4ba84432014-04-14 00:51:57 +0000211 AddrLabelSymbols = nullptr;
Matthias Braunfa5c5c72016-08-24 01:52:46 +0000212 TheModule = &M;
Matthias Braun08b668a2018-10-31 17:18:41 +0000213 DbgInfoAvailable = !empty(M.debug_compile_units());
Pedro Artigasd1abec32012-12-05 17:12:22 +0000214 return false;
215}
216
217bool MachineModuleInfo::doFinalization(Module &M) {
Pedro Artigasd1abec32012-12-05 17:12:22 +0000218 Personalities.clear();
219
Chris Lattner0220ba72010-03-15 19:09:43 +0000220 delete AddrLabelSymbols;
Craig Topper4ba84432014-04-14 00:51:57 +0000221 AddrLabelSymbols = nullptr;
Pedro Artigasd1abec32012-12-05 17:12:22 +0000222
Pedro Artigas5399d252012-12-12 22:59:46 +0000223 Context.reset();
Pedro Artigas873a1dd2012-12-06 22:12:44 +0000224
Pedro Artigasb9d10052013-01-04 18:04:42 +0000225 delete ObjFileMMI;
Craig Topper4ba84432014-04-14 00:51:57 +0000226 ObjFileMMI = nullptr;
Pedro Artigasb9d10052013-01-04 18:04:42 +0000227
Pedro Artigasd1abec32012-12-05 17:12:22 +0000228 return false;
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000229}
230
Chris Lattner0220ba72010-03-15 19:09:43 +0000231//===- Address of Block Management ----------------------------------------===//
232
Benjamin Kramer17d72152015-06-29 20:21:55 +0000233ArrayRef<MCSymbol *>
234MachineModuleInfo::getAddrLabelSymbolToEmit(const BasicBlock *BB) {
Chris Lattner999aee22010-03-16 00:29:39 +0000235 // Lazily create AddrLabelSymbols.
Craig Topper4ba84432014-04-14 00:51:57 +0000236 if (!AddrLabelSymbols)
Chris Lattner999aee22010-03-16 00:29:39 +0000237 AddrLabelSymbols = new MMIAddrLabelMap(Context);
238 return AddrLabelSymbols->getAddrLabelSymbolToEmit(const_cast<BasicBlock*>(BB));
239}
240
Chris Lattner9cc0da92010-03-15 20:39:00 +0000241void MachineModuleInfo::
242takeDeletedSymbolsForFunction(const Function *F,
243 std::vector<MCSymbol*> &Result) {
244 // If no blocks have had their addresses taken, we're done.
Craig Topper4ba84432014-04-14 00:51:57 +0000245 if (!AddrLabelSymbols) return;
Chris Lattner9cc0da92010-03-15 20:39:00 +0000246 return AddrLabelSymbols->
247 takeDeletedSymbolsForFunction(const_cast<Function*>(F), Result);
248}
Chris Lattner3b9d6212010-03-14 17:53:23 +0000249
Matthias Braun347847b2016-12-01 19:32:15 +0000250/// \name Exception Handling
251/// \{
Jim Laskey59667fe2007-02-21 22:38:31 +0000252
Keno Fischer890c1662015-07-14 19:22:51 +0000253void MachineModuleInfo::addPersonality(const Function *Personality) {
Bill Wendling10fff602008-07-03 22:53:42 +0000254 for (unsigned i = 0; i < Personalities.size(); ++i)
Anton Korobeynikov8c7c1732007-05-13 15:42:26 +0000255 if (Personalities[i] == Personality)
256 return;
Reid Kleckner7174af92015-08-31 20:02:16 +0000257 Personalities.push_back(Personality);
Jim Laskey59667fe2007-02-21 22:38:31 +0000258}
259
Matthias Braun347847b2016-12-01 19:32:15 +0000260/// \}
Matthias Braunfa5c5c72016-08-24 01:52:46 +0000261
Matthias Braun2144c522017-06-06 00:44:35 +0000262MachineFunction *
263MachineModuleInfo::getMachineFunction(const Function &F) const {
264 auto I = MachineFunctions.find(&F);
265 return I != MachineFunctions.end() ? I->second.get() : nullptr;
266}
267
268MachineFunction &
269MachineModuleInfo::getOrCreateMachineFunction(const Function &F) {
Matthias Braunfa5c5c72016-08-24 01:52:46 +0000270 // Shortcut for the common case where a sequence of MachineFunctionPasses
271 // all query for the same Function.
272 if (LastRequest == &F)
273 return *LastResult;
274
275 auto I = MachineFunctions.insert(
276 std::make_pair(&F, std::unique_ptr<MachineFunction>()));
277 MachineFunction *MF;
278 if (I.second) {
279 // No pre-existing machine function, create a new one.
Matthias Braundfcb4f52017-12-15 22:22:46 +0000280 const TargetSubtargetInfo &STI = *TM.getSubtargetImpl(F);
281 MF = new MachineFunction(F, TM, STI, NextFnNum++, *this);
Matthias Braunfa5c5c72016-08-24 01:52:46 +0000282 // Update the set entry.
283 I.first->second.reset(MF);
Matthias Braunfa5c5c72016-08-24 01:52:46 +0000284 } else {
285 MF = I.first->second.get();
286 }
287
288 LastRequest = &F;
289 LastResult = MF;
290 return *MF;
291}
292
293void MachineModuleInfo::deleteMachineFunctionFor(Function &F) {
294 MachineFunctions.erase(&F);
295 LastRequest = nullptr;
296 LastResult = nullptr;
297}
298
299namespace {
Eugene Zelenko1d081e62017-05-31 01:10:10 +0000300
Matthias Braunfa5c5c72016-08-24 01:52:46 +0000301/// This pass frees the MachineFunction object associated with a Function.
302class FreeMachineFunction : public FunctionPass {
303public:
304 static char ID;
Eugene Zelenko1d081e62017-05-31 01:10:10 +0000305
Matthias Braunfa5c5c72016-08-24 01:52:46 +0000306 FreeMachineFunction() : FunctionPass(ID) {}
307
308 void getAnalysisUsage(AnalysisUsage &AU) const override {
309 AU.addRequired<MachineModuleInfo>();
310 AU.addPreserved<MachineModuleInfo>();
311 }
312
313 bool runOnFunction(Function &F) override {
314 MachineModuleInfo &MMI = getAnalysis<MachineModuleInfo>();
315 MMI.deleteMachineFunctionFor(F);
316 return true;
317 }
Fangrui Songaf7b1832018-07-30 19:41:25 +0000318
Yaron Kerendebb02e2017-03-07 20:59:08 +0000319 StringRef getPassName() const override {
320 return "Free MachineFunction";
Fangrui Songaf7b1832018-07-30 19:41:25 +0000321 }
Matthias Braunfa5c5c72016-08-24 01:52:46 +0000322};
Eugene Zelenko1d081e62017-05-31 01:10:10 +0000323
Matthias Braunfa5c5c72016-08-24 01:52:46 +0000324} // end anonymous namespace
325
Eugene Zelenko1d081e62017-05-31 01:10:10 +0000326char FreeMachineFunction::ID;
327
328FunctionPass *llvm::createFreeMachineFunctionPass() {
Matthias Braunfa5c5c72016-08-24 01:52:46 +0000329 return new FreeMachineFunction();
330}
Ahmed Bougachaf522e202016-11-16 22:24:56 +0000331
332//===- MMI building helpers -----------------------------------------------===//
333
Ahmed Bougacha03cebfb2016-11-16 22:25:03 +0000334void llvm::computeUsesVAFloatArgument(const CallInst &I,
335 MachineModuleInfo &MMI) {
Ahmed Bougachaf522e202016-11-16 22:24:56 +0000336 FunctionType *FT =
337 cast<FunctionType>(I.getCalledValue()->getType()->getContainedType(0));
Ahmed Bougacha03cebfb2016-11-16 22:25:03 +0000338 if (FT->isVarArg() && !MMI.usesVAFloatArgument()) {
Ahmed Bougachaf522e202016-11-16 22:24:56 +0000339 for (unsigned i = 0, e = I.getNumArgOperands(); i != e; ++i) {
340 Type *T = I.getArgOperand(i)->getType();
341 for (auto i : post_order(T)) {
342 if (i->isFloatingPointTy()) {
Ahmed Bougacha03cebfb2016-11-16 22:25:03 +0000343 MMI.setUsesVAFloatArgument(true);
Ahmed Bougachaf522e202016-11-16 22:24:56 +0000344 return;
345 }
346 }
347 }
348 }
349}