blob: 054cc97f8374e1eb17688f04938d64f90de61ed8 [file] [log] [blame]
Jim Laskey5a1df972007-01-26 21:38:26 +00001//===-- llvm/CodeGen/MachineModuleInfo.cpp ----------------------*- C++ -*-===//
Jim Laskey44317392006-01-04 13:36:38 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Laskey44317392006-01-04 13:36:38 +00007//
8//===----------------------------------------------------------------------===//
Jim Laskey44317392006-01-04 13:36:38 +00009
Chandler Carruth6bda14b2017-06-06 11:49:48 +000010#include "llvm/CodeGen/MachineModuleInfo.h"
Eugene Zelenko4e9736b2017-05-31 01:10:10 +000011#include "llvm/ADT/ArrayRef.h"
12#include "llvm/ADT/DenseMap.h"
Ahmed Bougacha456dce82016-11-16 22:24:56 +000013#include "llvm/ADT/PostOrderIterator.h"
Eugene Zelenko4e9736b2017-05-31 01:10:10 +000014#include "llvm/ADT/StringRef.h"
Reid Klecknerc20276d2015-11-17 21:10:25 +000015#include "llvm/ADT/TinyPtrVector.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000016#include "llvm/CodeGen/MachineFunction.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000017#include "llvm/CodeGen/Passes.h"
Eugene Zelenko4e9736b2017-05-31 01:10:10 +000018#include "llvm/IR/BasicBlock.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000019#include "llvm/IR/DerivedTypes.h"
Ahmed Bougacha456dce82016-11-16 22:24:56 +000020#include "llvm/IR/Instructions.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000021#include "llvm/IR/Module.h"
Eugene Zelenko4e9736b2017-05-31 01:10:10 +000022#include "llvm/IR/Value.h"
23#include "llvm/IR/ValueHandle.h"
24#include "llvm/MC/MCContext.h"
Chris Lattner34adc8d2010-03-14 01:41:15 +000025#include "llvm/MC/MCSymbol.h"
Eugene Zelenko4e9736b2017-05-31 01:10:10 +000026#include "llvm/Pass.h"
27#include "llvm/Support/Casting.h"
Torok Edwin56d06592009-07-11 20:10:48 +000028#include "llvm/Support/ErrorHandling.h"
David Blaikie6054e652018-03-23 23:58:19 +000029#include "llvm/Target/TargetLoweringObjectFile.h"
Matthias Braunc3b2e802016-08-24 00:42:05 +000030#include "llvm/Target/TargetMachine.h"
Eugene Zelenko4e9736b2017-05-31 01:10:10 +000031#include <algorithm>
32#include <cassert>
33#include <memory>
34#include <utility>
35#include <vector>
36
Jim Laskey44317392006-01-04 13:36:38 +000037using namespace llvm;
Jim Laskey4e71db12006-03-01 20:39:36 +000038using namespace llvm::dwarf;
Jim Laskey44317392006-01-04 13:36:38 +000039
Micah Villmowcdfe20b2012-10-08 16:38:25 +000040// Handle the Pass registration stuff necessary to use DataLayout's.
Francis Visoiu Mistrih8b617642017-05-18 17:21:13 +000041INITIALIZE_PASS(MachineModuleInfo, "machinemoduleinfo",
42 "Machine Module Information", false, false)
Devang Patel8c78a0b2007-05-03 01:11:54 +000043char MachineModuleInfo::ID = 0;
Jim Laskeyb9966022006-01-17 17:31:53 +000044
Chris Lattnerf2471ec2009-09-15 22:44:26 +000045// Out of line virtual method.
Eugene Zelenko4e9736b2017-05-31 01:10:10 +000046MachineModuleInfoImpl::~MachineModuleInfoImpl() = default;
Chris Lattnerf2471ec2009-09-15 22:44:26 +000047
Chris Lattner347a0eb2010-03-15 19:09:43 +000048namespace llvm {
Eugene Zelenko4e9736b2017-05-31 01:10:10 +000049
David Blaikie774b5842015-08-03 22:30:24 +000050class MMIAddrLabelMapCallbackPtr final : CallbackVH {
Eugene Zelenko4e9736b2017-05-31 01:10:10 +000051 MMIAddrLabelMap *Map = nullptr;
52
Chris Lattner347a0eb2010-03-15 19:09:43 +000053public:
Eugene Zelenko4e9736b2017-05-31 01:10:10 +000054 MMIAddrLabelMapCallbackPtr() = default;
55 MMIAddrLabelMapCallbackPtr(Value *V) : CallbackVH(V) {}
Michael J. Spencerd3ea25e2010-10-16 08:25:21 +000056
Chris Lattnerb1c4f622010-03-22 23:15:57 +000057 void setPtr(BasicBlock *BB) {
58 ValueHandleBase::operator=(BB);
59 }
Michael J. Spencerd3ea25e2010-10-16 08:25:21 +000060
Chris Lattner347a0eb2010-03-15 19:09:43 +000061 void setMap(MMIAddrLabelMap *map) { Map = map; }
Michael J. Spencerd3ea25e2010-10-16 08:25:21 +000062
Craig Topper4584cd52014-03-07 09:26:03 +000063 void deleted() override;
64 void allUsesReplacedWith(Value *V2) override;
Chris Lattner347a0eb2010-03-15 19:09:43 +000065};
Michael J. Spencerd3ea25e2010-10-16 08:25:21 +000066
Chris Lattner347a0eb2010-03-15 19:09:43 +000067class MMIAddrLabelMap {
68 MCContext &Context;
69 struct AddrLabelSymEntry {
Ahmed Bougacha2b4c1272016-11-16 22:24:53 +000070 /// The symbols for the label.
Benjamin Kramer6fe4e792015-06-29 20:21:55 +000071 TinyPtrVector<MCSymbol *> Symbols;
Michael J. Spencerd3ea25e2010-10-16 08:25:21 +000072
Chris Lattner561334a2010-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 Lattner347a0eb2010-03-15 19:09:43 +000075 };
Michael J. Spencerd3ea25e2010-10-16 08:25:21 +000076
Chris Lattner347a0eb2010-03-15 19:09:43 +000077 DenseMap<AssertingVH<BasicBlock>, AddrLabelSymEntry> AddrLabelSymbols;
Michael J. Spencerd3ea25e2010-10-16 08:25:21 +000078
Ahmed Bougacha2b4c1272016-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 Lattner347a0eb2010-03-15 19:09:43 +000081 std::vector<MMIAddrLabelMapCallbackPtr> BBCallbacks;
Chris Lattner561334a2010-03-15 20:39:00 +000082
Ahmed Bougacha2b4c1272016-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 Zelenko4e9736b2017-05-31 01:10:10 +000086 DenseMap<AssertingVH<Function>, std::vector<MCSymbol*>>
Chris Lattner561334a2010-03-15 20:39:00 +000087 DeletedAddrLabelsNeedingEmission;
Michael J. Spencerd3ea25e2010-10-16 08:25:21 +000088
Eugene Zelenko4e9736b2017-05-31 01:10:10 +000089public:
Chris Lattner347a0eb2010-03-15 19:09:43 +000090 MMIAddrLabelMap(MCContext &context) : Context(context) {}
Eugene Zelenko4e9736b2017-05-31 01:10:10 +000091
Chris Lattner561334a2010-03-15 20:39:00 +000092 ~MMIAddrLabelMap() {
93 assert(DeletedAddrLabelsNeedingEmission.empty() &&
94 "Some labels for deleted blocks never got emitted");
95 }
Michael J. Spencerd3ea25e2010-10-16 08:25:21 +000096
Benjamin Kramer6fe4e792015-06-29 20:21:55 +000097 ArrayRef<MCSymbol *> getAddrLabelSymbolToEmit(BasicBlock *BB);
Chris Lattnerdb035a02010-03-16 00:29:39 +000098
Michael J. Spencerd3ea25e2010-10-16 08:25:21 +000099 void takeDeletedSymbolsForFunction(Function *F,
Chris Lattner561334a2010-03-15 20:39:00 +0000100 std::vector<MCSymbol*> &Result);
101
Chris Lattner347a0eb2010-03-15 19:09:43 +0000102 void UpdateForDeletedBlock(BasicBlock *BB);
103 void UpdateForRAUWBlock(BasicBlock *Old, BasicBlock *New);
104};
Eugene Zelenko4e9736b2017-05-31 01:10:10 +0000105
106} // end namespace llvm
Chris Lattner347a0eb2010-03-15 19:09:43 +0000107
Benjamin Kramer6fe4e792015-06-29 20:21:55 +0000108ArrayRef<MCSymbol *> MMIAddrLabelMap::getAddrLabelSymbolToEmit(BasicBlock *BB) {
Chris Lattner347a0eb2010-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. Spencerd3ea25e2010-10-16 08:25:21 +0000112
Chris Lattner347a0eb2010-03-15 19:09:43 +0000113 // If we already had an entry for this block, just return it.
Benjamin Kramer6fe4e792015-06-29 20:21:55 +0000114 if (!Entry.Symbols.empty()) {
Chris Lattner561334a2010-03-15 20:39:00 +0000115 assert(BB->getParent() == Entry.Fn && "Parent changed");
Benjamin Kramer6fe4e792015-06-29 20:21:55 +0000116 return Entry.Symbols;
Chris Lattner561334a2010-03-15 20:39:00 +0000117 }
Michael J. Spencerd3ea25e2010-10-16 08:25:21 +0000118
Chris Lattner347a0eb2010-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 Kramerf5e2fc42015-05-29 19:43:39 +0000121 BBCallbacks.emplace_back(BB);
Chris Lattner347a0eb2010-03-15 19:09:43 +0000122 BBCallbacks.back().setMap(this);
Benjamin Kramer6fe4e792015-06-29 20:21:55 +0000123 Entry.Index = BBCallbacks.size() - 1;
Chris Lattner561334a2010-03-15 20:39:00 +0000124 Entry.Fn = BB->getParent();
Benjamin Kramer6fe4e792015-06-29 20:21:55 +0000125 Entry.Symbols.push_back(Context.createTempSymbol());
126 return Entry.Symbols;
Chris Lattner347a0eb2010-03-15 19:09:43 +0000127}
128
Ahmed Bougacha2b4c1272016-11-16 22:24:53 +0000129/// If we have any deleted symbols for F, return them.
Chris Lattner561334a2010-03-15 20:39:00 +0000130void MMIAddrLabelMap::
131takeDeletedSymbolsForFunction(Function *F, std::vector<MCSymbol*> &Result) {
Eugene Zelenko4e9736b2017-05-31 01:10:10 +0000132 DenseMap<AssertingVH<Function>, std::vector<MCSymbol*>>::iterator I =
Chris Lattner561334a2010-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. Spencerd3ea25e2010-10-16 08:25:21 +0000137
Chris Lattner561334a2010-03-15 20:39:00 +0000138 // Otherwise, take the list.
139 std::swap(Result, I->second);
140 DeletedAddrLabelsNeedingEmission.erase(I);
141}
142
Chris Lattner347a0eb2010-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 Kramer6fe4e792015-06-29 20:21:55 +0000147 AddrLabelSymEntry Entry = std::move(AddrLabelSymbols[BB]);
Chris Lattner347a0eb2010-03-15 19:09:43 +0000148 AddrLabelSymbols.erase(BB);
Benjamin Kramer6fe4e792015-06-29 20:21:55 +0000149 assert(!Entry.Symbols.empty() && "Didn't have a symbol, why a callback?");
Craig Topperc0196b12014-04-14 00:51:57 +0000150 BBCallbacks[Entry.Index] = nullptr; // Clear the callback.
Chris Lattner347a0eb2010-03-15 19:09:43 +0000151
Craig Topperc0196b12014-04-14 00:51:57 +0000152 assert((BB->getParent() == nullptr || BB->getParent() == Entry.Fn) &&
Chris Lattner561334a2010-03-15 20:39:00 +0000153 "Block/parent mismatch");
Chris Lattnerdb035a02010-03-16 00:29:39 +0000154
Benjamin Kramer6fe4e792015-06-29 20:21:55 +0000155 for (MCSymbol *Sym : Entry.Symbols) {
Chris Lattnerdb035a02010-03-16 00:29:39 +0000156 if (Sym->isDefined())
157 return;
Michael J. Spencerd3ea25e2010-10-16 08:25:21 +0000158
Chris Lattnerdb035a02010-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 Lattnerdb035a02010-03-16 00:29:39 +0000164 }
Chris Lattner347a0eb2010-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 Kramer6fe4e792015-06-29 20:21:55 +0000169 AddrLabelSymEntry OldEntry = std::move(AddrLabelSymbols[Old]);
Chris Lattner347a0eb2010-03-15 19:09:43 +0000170 AddrLabelSymbols.erase(Old);
Benjamin Kramer6fe4e792015-06-29 20:21:55 +0000171 assert(!OldEntry.Symbols.empty() && "Didn't have a symbol, why a callback?");
Chris Lattnerdb035a02010-03-16 00:29:39 +0000172
173 AddrLabelSymEntry &NewEntry = AddrLabelSymbols[New];
174
Chris Lattner347a0eb2010-03-15 19:09:43 +0000175 // If New is not address taken, just move our symbol over to it.
Benjamin Kramer6fe4e792015-06-29 20:21:55 +0000176 if (NewEntry.Symbols.empty()) {
Chris Lattnerb1c4f622010-03-22 23:15:57 +0000177 BBCallbacks[OldEntry.Index].setPtr(New); // Update the callback.
Benjamin Kramer6fe4e792015-06-29 20:21:55 +0000178 NewEntry = std::move(OldEntry); // Set New's entry.
Chris Lattnerdb035a02010-03-16 00:29:39 +0000179 return;
Chris Lattner347a0eb2010-03-15 19:09:43 +0000180 }
Chris Lattnerdb035a02010-03-16 00:29:39 +0000181
Craig Topperc0196b12014-04-14 00:51:57 +0000182 BBCallbacks[OldEntry.Index] = nullptr; // Update the callback.
Chris Lattnerdb035a02010-03-16 00:29:39 +0000183
Benjamin Kramer6fe4e792015-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 Lattner347a0eb2010-03-15 19:09:43 +0000187}
188
Chris Lattner347a0eb2010-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 Braunc3b2e802016-08-24 00:42:05 +0000197MachineModuleInfo::MachineModuleInfo(const TargetMachine *TM)
Matthias Braun733fe362016-08-24 01:52:46 +0000198 : ImmutablePass(ID), TM(*TM),
199 Context(TM->getMCAsmInfo(), TM->getMCRegisterInfo(),
200 TM->getObjFileLowering(), nullptr, false) {
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000201 initializeMachineModuleInfoPass(*PassRegistry::getPassRegistry());
Anton Korobeynikovbbaf5542007-05-13 15:42:26 +0000202}
Jim Laskey0bbdc552006-01-26 20:21:46 +0000203
Eugene Zelenko4e9736b2017-05-31 01:10:10 +0000204MachineModuleInfo::~MachineModuleInfo() = default;
Michael J. Spencerd3ea25e2010-10-16 08:25:21 +0000205
Pedro Artigas41b98842012-12-05 17:12:22 +0000206bool MachineModuleInfo::doInitialization(Module &M) {
Craig Topperc0196b12014-04-14 00:51:57 +0000207 ObjFileMMI = nullptr;
Pedro Artigas41b98842012-12-05 17:12:22 +0000208 CurCallSite = 0;
Peter Collingbourne7ef497b2014-12-30 20:05:19 +0000209 DbgInfoAvailable = UsesVAFloatArgument = UsesMorestackAddr = false;
Than McIntoshdee2cf62017-09-27 19:34:00 +0000210 HasSplitStack = HasNosplitStack = false;
Craig Topperc0196b12014-04-14 00:51:57 +0000211 AddrLabelSymbols = nullptr;
Matthias Braun733fe362016-08-24 01:52:46 +0000212 TheModule = &M;
Pedro Artigas41b98842012-12-05 17:12:22 +0000213 return false;
214}
215
216bool MachineModuleInfo::doFinalization(Module &M) {
Pedro Artigas41b98842012-12-05 17:12:22 +0000217 Personalities.clear();
218
Chris Lattner347a0eb2010-03-15 19:09:43 +0000219 delete AddrLabelSymbols;
Craig Topperc0196b12014-04-14 00:51:57 +0000220 AddrLabelSymbols = nullptr;
Pedro Artigas41b98842012-12-05 17:12:22 +0000221
Pedro Artigas7212ee42012-12-12 22:59:46 +0000222 Context.reset();
Pedro Artigase84b13f2012-12-06 22:12:44 +0000223
Pedro Artigas33832252013-01-04 18:04:42 +0000224 delete ObjFileMMI;
Craig Topperc0196b12014-04-14 00:51:57 +0000225 ObjFileMMI = nullptr;
Pedro Artigas33832252013-01-04 18:04:42 +0000226
Pedro Artigas41b98842012-12-05 17:12:22 +0000227 return false;
Jim Laskey0bbdc552006-01-26 20:21:46 +0000228}
229
Chris Lattner347a0eb2010-03-15 19:09:43 +0000230//===- Address of Block Management ----------------------------------------===//
231
Benjamin Kramer6fe4e792015-06-29 20:21:55 +0000232ArrayRef<MCSymbol *>
233MachineModuleInfo::getAddrLabelSymbolToEmit(const BasicBlock *BB) {
Chris Lattnerdb035a02010-03-16 00:29:39 +0000234 // Lazily create AddrLabelSymbols.
Craig Topperc0196b12014-04-14 00:51:57 +0000235 if (!AddrLabelSymbols)
Chris Lattnerdb035a02010-03-16 00:29:39 +0000236 AddrLabelSymbols = new MMIAddrLabelMap(Context);
237 return AddrLabelSymbols->getAddrLabelSymbolToEmit(const_cast<BasicBlock*>(BB));
238}
239
Chris Lattner561334a2010-03-15 20:39:00 +0000240void MachineModuleInfo::
241takeDeletedSymbolsForFunction(const Function *F,
242 std::vector<MCSymbol*> &Result) {
243 // If no blocks have had their addresses taken, we're done.
Craig Topperc0196b12014-04-14 00:51:57 +0000244 if (!AddrLabelSymbols) return;
Chris Lattner561334a2010-03-15 20:39:00 +0000245 return AddrLabelSymbols->
246 takeDeletedSymbolsForFunction(const_cast<Function*>(F), Result);
247}
Chris Lattner9efbbcb2010-03-14 17:53:23 +0000248
Matthias Braund0ee66c2016-12-01 19:32:15 +0000249/// \name Exception Handling
250/// \{
Jim Laskey88dd2fd2007-02-21 22:38:31 +0000251
Keno Fischeraff703a2015-07-14 19:22:51 +0000252void MachineModuleInfo::addPersonality(const Function *Personality) {
Bill Wendling2e5068942008-07-03 22:53:42 +0000253 for (unsigned i = 0; i < Personalities.size(); ++i)
Anton Korobeynikovbbaf5542007-05-13 15:42:26 +0000254 if (Personalities[i] == Personality)
255 return;
Reid Klecknere00faf82015-08-31 20:02:16 +0000256 Personalities.push_back(Personality);
Jim Laskey88dd2fd2007-02-21 22:38:31 +0000257}
258
Matthias Braund0ee66c2016-12-01 19:32:15 +0000259/// \}
Matthias Braun733fe362016-08-24 01:52:46 +0000260
Matthias Braun7bda1952017-06-06 00:44:35 +0000261MachineFunction *
262MachineModuleInfo::getMachineFunction(const Function &F) const {
263 auto I = MachineFunctions.find(&F);
264 return I != MachineFunctions.end() ? I->second.get() : nullptr;
265}
266
267MachineFunction &
268MachineModuleInfo::getOrCreateMachineFunction(const Function &F) {
Matthias Braun733fe362016-08-24 01:52:46 +0000269 // Shortcut for the common case where a sequence of MachineFunctionPasses
270 // all query for the same Function.
271 if (LastRequest == &F)
272 return *LastResult;
273
274 auto I = MachineFunctions.insert(
275 std::make_pair(&F, std::unique_ptr<MachineFunction>()));
276 MachineFunction *MF;
277 if (I.second) {
278 // No pre-existing machine function, create a new one.
Matthias Braun46840332017-12-15 22:22:46 +0000279 const TargetSubtargetInfo &STI = *TM.getSubtargetImpl(F);
280 MF = new MachineFunction(F, TM, STI, NextFnNum++, *this);
Matthias Braun733fe362016-08-24 01:52:46 +0000281 // Update the set entry.
282 I.first->second.reset(MF);
Matthias Braun733fe362016-08-24 01:52:46 +0000283 } else {
284 MF = I.first->second.get();
285 }
286
287 LastRequest = &F;
288 LastResult = MF;
289 return *MF;
290}
291
292void MachineModuleInfo::deleteMachineFunctionFor(Function &F) {
293 MachineFunctions.erase(&F);
294 LastRequest = nullptr;
295 LastResult = nullptr;
296}
297
298namespace {
Eugene Zelenko4e9736b2017-05-31 01:10:10 +0000299
Matthias Braun733fe362016-08-24 01:52:46 +0000300/// This pass frees the MachineFunction object associated with a Function.
301class FreeMachineFunction : public FunctionPass {
302public:
303 static char ID;
Eugene Zelenko4e9736b2017-05-31 01:10:10 +0000304
Matthias Braun733fe362016-08-24 01:52:46 +0000305 FreeMachineFunction() : FunctionPass(ID) {}
306
307 void getAnalysisUsage(AnalysisUsage &AU) const override {
308 AU.addRequired<MachineModuleInfo>();
309 AU.addPreserved<MachineModuleInfo>();
310 }
311
312 bool runOnFunction(Function &F) override {
313 MachineModuleInfo &MMI = getAnalysis<MachineModuleInfo>();
314 MMI.deleteMachineFunctionFor(F);
315 return true;
316 }
Yaron Keren75fadfc2017-03-07 20:59:08 +0000317
318 StringRef getPassName() const override {
319 return "Free MachineFunction";
320 }
Matthias Braun733fe362016-08-24 01:52:46 +0000321};
Eugene Zelenko4e9736b2017-05-31 01:10:10 +0000322
Matthias Braun733fe362016-08-24 01:52:46 +0000323} // end anonymous namespace
324
Eugene Zelenko4e9736b2017-05-31 01:10:10 +0000325char FreeMachineFunction::ID;
326
327FunctionPass *llvm::createFreeMachineFunctionPass() {
Matthias Braun733fe362016-08-24 01:52:46 +0000328 return new FreeMachineFunction();
329}
Ahmed Bougacha456dce82016-11-16 22:24:56 +0000330
331//===- MMI building helpers -----------------------------------------------===//
332
Ahmed Bougachabd6ce9a2016-11-16 22:25:03 +0000333void llvm::computeUsesVAFloatArgument(const CallInst &I,
334 MachineModuleInfo &MMI) {
Ahmed Bougacha456dce82016-11-16 22:24:56 +0000335 FunctionType *FT =
336 cast<FunctionType>(I.getCalledValue()->getType()->getContainedType(0));
Ahmed Bougachabd6ce9a2016-11-16 22:25:03 +0000337 if (FT->isVarArg() && !MMI.usesVAFloatArgument()) {
Ahmed Bougacha456dce82016-11-16 22:24:56 +0000338 for (unsigned i = 0, e = I.getNumArgOperands(); i != e; ++i) {
339 Type *T = I.getArgOperand(i)->getType();
340 for (auto i : post_order(T)) {
341 if (i->isFloatingPointTy()) {
Ahmed Bougachabd6ce9a2016-11-16 22:25:03 +0000342 MMI.setUsesVAFloatArgument(true);
Ahmed Bougacha456dce82016-11-16 22:24:56 +0000343 return;
344 }
345 }
346 }
347 }
348}