LLVM  4.0.0
CodeExtractor.cpp
Go to the documentation of this file.
1 //===- CodeExtractor.cpp - Pull code region into a new function -----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the interface to tear out a code region, such as an
11 // individual loop or a parallel section, into a new function, replacing it with
12 // a call to the new function.
13 //
14 //===----------------------------------------------------------------------===//
15 
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/SetVector.h"
19 #include "llvm/ADT/StringExtras.h"
23 #include "llvm/Analysis/LoopInfo.h"
26 #include "llvm/IR/Constants.h"
27 #include "llvm/IR/DerivedTypes.h"
28 #include "llvm/IR/Dominators.h"
29 #include "llvm/IR/Instructions.h"
30 #include "llvm/IR/Intrinsics.h"
31 #include "llvm/IR/LLVMContext.h"
32 #include "llvm/IR/MDBuilder.h"
33 #include "llvm/IR/Module.h"
34 #include "llvm/IR/Verifier.h"
35 #include "llvm/Pass.h"
38 #include "llvm/Support/Debug.h"
42 #include <algorithm>
43 #include <set>
44 using namespace llvm;
45 
46 #define DEBUG_TYPE "code-extractor"
47 
48 // Provide a command-line option to aggregate function arguments into a struct
49 // for functions produced by the code extractor. This is useful when converting
50 // extracted functions to pthread-based code, as only one argument (void*) can
51 // be passed in to pthread_create().
52 static cl::opt<bool>
53 AggregateArgsOpt("aggregate-extracted-args", cl::Hidden,
54  cl::desc("Aggregate arguments to code-extracted functions"));
55 
56 /// \brief Test whether a block is valid for extraction.
58  // Landing pads must be in the function where they were inserted for cleanup.
59  if (BB.isEHPad())
60  return false;
61 
62  // Don't hoist code containing allocas, invokes, or vastarts.
63  for (BasicBlock::const_iterator I = BB.begin(), E = BB.end(); I != E; ++I) {
64  if (isa<AllocaInst>(I) || isa<InvokeInst>(I))
65  return false;
66  if (const CallInst *CI = dyn_cast<CallInst>(I))
67  if (const Function *F = CI->getCalledFunction())
68  if (F->getIntrinsicID() == Intrinsic::vastart)
69  return false;
70  }
71 
72  return true;
73 }
74 
75 /// \brief Build a set of blocks to extract if the input blocks are viable.
76 template <typename IteratorT>
78  IteratorT BBEnd) {
80 
81  assert(BBBegin != BBEnd);
82 
83  // Loop over the blocks, adding them to our set-vector, and aborting with an
84  // empty set if we encounter invalid blocks.
85  do {
86  if (!Result.insert(*BBBegin))
87  llvm_unreachable("Repeated basic blocks in extraction input");
88 
90  Result.clear();
91  return Result;
92  }
93  } while (++BBBegin != BBEnd);
94 
95 #ifndef NDEBUG
96  for (SetVector<BasicBlock *>::iterator I = std::next(Result.begin()),
97  E = Result.end();
98  I != E; ++I)
99  for (pred_iterator PI = pred_begin(*I), PE = pred_end(*I);
100  PI != PE; ++PI)
101  assert(Result.count(*PI) &&
102  "No blocks in this region may have entries from outside the region"
103  " except for the first block!");
104 #endif
105 
106  return Result;
107 }
108 
109 /// \brief Helper to call buildExtractionBlockSet with an ArrayRef.
112  return buildExtractionBlockSet(BBs.begin(), BBs.end());
113 }
114 
115 /// \brief Helper to call buildExtractionBlockSet with a RegionNode.
118  if (!RN.isSubRegion())
119  // Just a single BasicBlock.
121 
122  const Region &R = *RN.getNodeAs<Region>();
123 
125 }
126 
127 CodeExtractor::CodeExtractor(BasicBlock *BB, bool AggregateArgs,
130  : DT(nullptr), AggregateArgs(AggregateArgs || AggregateArgsOpt), BFI(BFI),
131  BPI(BPI), Blocks(buildExtractionBlockSet(BB)), NumExitBlocks(~0U) {}
132 
134  bool AggregateArgs, BlockFrequencyInfo *BFI,
136  : DT(DT), AggregateArgs(AggregateArgs || AggregateArgsOpt), BFI(BFI),
137  BPI(BPI), Blocks(buildExtractionBlockSet(BBs)), NumExitBlocks(~0U) {}
138 
142  : DT(&DT), AggregateArgs(AggregateArgs || AggregateArgsOpt), BFI(BFI),
143  BPI(BPI), Blocks(buildExtractionBlockSet(L.getBlocks())),
144  NumExitBlocks(~0U) {}
145 
147  bool AggregateArgs, BlockFrequencyInfo *BFI,
149  : DT(&DT), AggregateArgs(AggregateArgs || AggregateArgsOpt), BFI(BFI),
150  BPI(BPI), Blocks(buildExtractionBlockSet(RN)), NumExitBlocks(~0U) {}
151 
152 /// definedInRegion - Return true if the specified value is defined in the
153 /// extracted region.
154 static bool definedInRegion(const SetVector<BasicBlock *> &Blocks, Value *V) {
155  if (Instruction *I = dyn_cast<Instruction>(V))
156  if (Blocks.count(I->getParent()))
157  return true;
158  return false;
159 }
160 
161 /// definedInCaller - Return true if the specified value is defined in the
162 /// function being code extracted, but not in the region being extracted.
163 /// These values must be passed in as live-ins to the function.
164 static bool definedInCaller(const SetVector<BasicBlock *> &Blocks, Value *V) {
165  if (isa<Argument>(V)) return true;
166  if (Instruction *I = dyn_cast<Instruction>(V))
167  if (!Blocks.count(I->getParent()))
168  return true;
169  return false;
170 }
171 
173  ValueSet &Outputs) const {
174  for (BasicBlock *BB : Blocks) {
175  // If a used value is defined outside the region, it's an input. If an
176  // instruction is used outside the region, it's an output.
177  for (Instruction &II : *BB) {
178  for (User::op_iterator OI = II.op_begin(), OE = II.op_end(); OI != OE;
179  ++OI)
180  if (definedInCaller(Blocks, *OI))
181  Inputs.insert(*OI);
182 
183  for (User *U : II.users())
184  if (!definedInRegion(Blocks, U)) {
185  Outputs.insert(&II);
186  break;
187  }
188  }
189  }
190 }
191 
192 /// severSplitPHINodes - If a PHI node has multiple inputs from outside of the
193 /// region, we need to split the entry block of the region so that the PHI node
194 /// is easier to deal with.
195 void CodeExtractor::severSplitPHINodes(BasicBlock *&Header) {
196  unsigned NumPredsFromRegion = 0;
197  unsigned NumPredsOutsideRegion = 0;
198 
199  if (Header != &Header->getParent()->getEntryBlock()) {
200  PHINode *PN = dyn_cast<PHINode>(Header->begin());
201  if (!PN) return; // No PHI nodes.
202 
203  // If the header node contains any PHI nodes, check to see if there is more
204  // than one entry from outside the region. If so, we need to sever the
205  // header block into two.
206  for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
207  if (Blocks.count(PN->getIncomingBlock(i)))
208  ++NumPredsFromRegion;
209  else
210  ++NumPredsOutsideRegion;
211 
212  // If there is one (or fewer) predecessor from outside the region, we don't
213  // need to do anything special.
214  if (NumPredsOutsideRegion <= 1) return;
215  }
216 
217  // Otherwise, we need to split the header block into two pieces: one
218  // containing PHI nodes merging values from outside of the region, and a
219  // second that contains all of the code for the block and merges back any
220  // incoming values from inside of the region.
221  BasicBlock::iterator AfterPHIs = Header->getFirstNonPHI()->getIterator();
222  BasicBlock *NewBB = Header->splitBasicBlock(AfterPHIs,
223  Header->getName()+".ce");
224 
225  // We only want to code extract the second block now, and it becomes the new
226  // header of the region.
227  BasicBlock *OldPred = Header;
228  Blocks.remove(OldPred);
229  Blocks.insert(NewBB);
230  Header = NewBB;
231 
232  // Okay, update dominator sets. The blocks that dominate the new one are the
233  // blocks that dominate TIBB plus the new block itself.
234  if (DT)
235  DT->splitBlock(NewBB);
236 
237  // Okay, now we need to adjust the PHI nodes and any branches from within the
238  // region to go to the new header block instead of the old header block.
239  if (NumPredsFromRegion) {
240  PHINode *PN = cast<PHINode>(OldPred->begin());
241  // Loop over all of the predecessors of OldPred that are in the region,
242  // changing them to branch to NewBB instead.
243  for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
244  if (Blocks.count(PN->getIncomingBlock(i))) {
246  TI->replaceUsesOfWith(OldPred, NewBB);
247  }
248 
249  // Okay, everything within the region is now branching to the right block, we
250  // just have to update the PHI nodes now, inserting PHI nodes into NewBB.
251  for (AfterPHIs = OldPred->begin(); isa<PHINode>(AfterPHIs); ++AfterPHIs) {
252  PHINode *PN = cast<PHINode>(AfterPHIs);
253  // Create a new PHI node in the new region, which has an incoming value
254  // from OldPred of PN.
255  PHINode *NewPN = PHINode::Create(PN->getType(), 1 + NumPredsFromRegion,
256  PN->getName() + ".ce", &NewBB->front());
257  NewPN->addIncoming(PN, OldPred);
258 
259  // Loop over all of the incoming value in PN, moving them to NewPN if they
260  // are from the extracted region.
261  for (unsigned i = 0; i != PN->getNumIncomingValues(); ++i) {
262  if (Blocks.count(PN->getIncomingBlock(i))) {
263  NewPN->addIncoming(PN->getIncomingValue(i), PN->getIncomingBlock(i));
264  PN->removeIncomingValue(i);
265  --i;
266  }
267  }
268  }
269  }
270 }
271 
272 void CodeExtractor::splitReturnBlocks() {
273  for (BasicBlock *Block : Blocks)
274  if (ReturnInst *RI = dyn_cast<ReturnInst>(Block->getTerminator())) {
275  BasicBlock *New =
276  Block->splitBasicBlock(RI->getIterator(), Block->getName() + ".ret");
277  if (DT) {
278  // Old dominates New. New node dominates all other nodes dominated
279  // by Old.
280  DomTreeNode *OldNode = DT->getNode(Block);
281  SmallVector<DomTreeNode *, 8> Children(OldNode->begin(),
282  OldNode->end());
283 
284  DomTreeNode *NewNode = DT->addNewBlock(New, Block);
285 
286  for (DomTreeNode *I : Children)
287  DT->changeImmediateDominator(I, NewNode);
288  }
289  }
290 }
291 
292 /// constructFunction - make a function based on inputs and outputs, as follows:
293 /// f(in0, ..., inN, out0, ..., outN)
294 ///
295 Function *CodeExtractor::constructFunction(const ValueSet &inputs,
296  const ValueSet &outputs,
297  BasicBlock *header,
298  BasicBlock *newRootNode,
299  BasicBlock *newHeader,
300  Function *oldFunction,
301  Module *M) {
302  DEBUG(dbgs() << "inputs: " << inputs.size() << "\n");
303  DEBUG(dbgs() << "outputs: " << outputs.size() << "\n");
304 
305  // This function returns unsigned, outputs will go back by reference.
306  switch (NumExitBlocks) {
307  case 0:
308  case 1: RetTy = Type::getVoidTy(header->getContext()); break;
309  case 2: RetTy = Type::getInt1Ty(header->getContext()); break;
310  default: RetTy = Type::getInt16Ty(header->getContext()); break;
311  }
312 
313  std::vector<Type*> paramTy;
314 
315  // Add the types of the input values to the function's argument list
316  for (Value *value : inputs) {
317  DEBUG(dbgs() << "value used in func: " << *value << "\n");
318  paramTy.push_back(value->getType());
319  }
320 
321  // Add the types of the output values to the function's argument list.
322  for (Value *output : outputs) {
323  DEBUG(dbgs() << "instr used in func: " << *output << "\n");
324  if (AggregateArgs)
325  paramTy.push_back(output->getType());
326  else
327  paramTy.push_back(PointerType::getUnqual(output->getType()));
328  }
329 
330  DEBUG({
331  dbgs() << "Function type: " << *RetTy << " f(";
332  for (Type *i : paramTy)
333  dbgs() << *i << ", ";
334  dbgs() << ")\n";
335  });
336 
337  StructType *StructTy;
338  if (AggregateArgs && (inputs.size() + outputs.size() > 0)) {
339  StructTy = StructType::get(M->getContext(), paramTy);
340  paramTy.clear();
341  paramTy.push_back(PointerType::getUnqual(StructTy));
342  }
343  FunctionType *funcType =
344  FunctionType::get(RetTy, paramTy, false);
345 
346  // Create the new function
347  Function *newFunction = Function::Create(funcType,
349  oldFunction->getName() + "_" +
350  header->getName(), M);
351  // If the old function is no-throw, so is the new one.
352  if (oldFunction->doesNotThrow())
353  newFunction->setDoesNotThrow();
354 
355  // Inherit the uwtable attribute if we need to.
356  if (oldFunction->hasUWTable())
357  newFunction->setHasUWTable();
358 
359  // Inherit all of the target dependent attributes.
360  // (e.g. If the extracted region contains a call to an x86.sse
361  // instruction we need to make sure that the extracted region has the
362  // "target-features" attribute allowing it to be lowered.
363  // FIXME: This should be changed to check to see if a specific
364  // attribute can not be inherited.
365  AttributeSet OldFnAttrs = oldFunction->getAttributes().getFnAttributes();
367  for (auto Attr : AB.td_attrs())
368  newFunction->addFnAttr(Attr.first, Attr.second);
369 
370  newFunction->getBasicBlockList().push_back(newRootNode);
371 
372  // Create an iterator to name all of the arguments we inserted.
373  Function::arg_iterator AI = newFunction->arg_begin();
374 
375  // Rewrite all users of the inputs in the extracted region to use the
376  // arguments (or appropriate addressing into struct) instead.
377  for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
378  Value *RewriteVal;
379  if (AggregateArgs) {
380  Value *Idx[2];
382  Idx[1] = ConstantInt::get(Type::getInt32Ty(header->getContext()), i);
383  TerminatorInst *TI = newFunction->begin()->getTerminator();
385  StructTy, &*AI, Idx, "gep_" + inputs[i]->getName(), TI);
386  RewriteVal = new LoadInst(GEP, "loadgep_" + inputs[i]->getName(), TI);
387  } else
388  RewriteVal = &*AI++;
389 
390  std::vector<User*> Users(inputs[i]->user_begin(), inputs[i]->user_end());
391  for (User *use : Users)
392  if (Instruction *inst = dyn_cast<Instruction>(use))
393  if (Blocks.count(inst->getParent()))
394  inst->replaceUsesOfWith(inputs[i], RewriteVal);
395  }
396 
397  // Set names for input and output arguments.
398  if (!AggregateArgs) {
399  AI = newFunction->arg_begin();
400  for (unsigned i = 0, e = inputs.size(); i != e; ++i, ++AI)
401  AI->setName(inputs[i]->getName());
402  for (unsigned i = 0, e = outputs.size(); i != e; ++i, ++AI)
403  AI->setName(outputs[i]->getName()+".out");
404  }
405 
406  // Rewrite branches to basic blocks outside of the loop to new dummy blocks
407  // within the new function. This must be done before we lose track of which
408  // blocks were originally in the code region.
409  std::vector<User*> Users(header->user_begin(), header->user_end());
410  for (unsigned i = 0, e = Users.size(); i != e; ++i)
411  // The BasicBlock which contains the branch is not in the region
412  // modify the branch target to a new block
413  if (TerminatorInst *TI = dyn_cast<TerminatorInst>(Users[i]))
414  if (!Blocks.count(TI->getParent()) &&
415  TI->getParent()->getParent() == oldFunction)
416  TI->replaceUsesOfWith(header, newHeader);
417 
418  return newFunction;
419 }
420 
421 /// FindPhiPredForUseInBlock - Given a value and a basic block, find a PHI
422 /// that uses the value within the basic block, and return the predecessor
423 /// block associated with that use, or return 0 if none is found.
425  for (Use &U : Used->uses()) {
426  PHINode *P = dyn_cast<PHINode>(U.getUser());
427  if (P && P->getParent() == BB)
428  return P->getIncomingBlock(U);
429  }
430 
431  return nullptr;
432 }
433 
434 /// emitCallAndSwitchStatement - This method sets up the caller side by adding
435 /// the call instruction, splitting any PHI nodes in the header block as
436 /// necessary.
437 void CodeExtractor::
438 emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
439  ValueSet &inputs, ValueSet &outputs) {
440  // Emit a call to the new function, passing in: *pointer to struct (if
441  // aggregating parameters), or plan inputs and allocated memory for outputs
442  std::vector<Value*> params, StructValues, ReloadOutputs, Reloads;
443 
444  LLVMContext &Context = newFunction->getContext();
445 
446  // Add inputs as params, or to be filled into the struct
447  for (Value *input : inputs)
448  if (AggregateArgs)
449  StructValues.push_back(input);
450  else
451  params.push_back(input);
452 
453  // Create allocas for the outputs
454  for (Value *output : outputs) {
455  if (AggregateArgs) {
456  StructValues.push_back(output);
457  } else {
458  AllocaInst *alloca =
459  new AllocaInst(output->getType(), nullptr, output->getName() + ".loc",
460  &codeReplacer->getParent()->front().front());
461  ReloadOutputs.push_back(alloca);
462  params.push_back(alloca);
463  }
464  }
465 
466  StructType *StructArgTy = nullptr;
467  AllocaInst *Struct = nullptr;
468  if (AggregateArgs && (inputs.size() + outputs.size() > 0)) {
469  std::vector<Type*> ArgTypes;
470  for (ValueSet::iterator v = StructValues.begin(),
471  ve = StructValues.end(); v != ve; ++v)
472  ArgTypes.push_back((*v)->getType());
473 
474  // Allocate a struct at the beginning of this function
475  StructArgTy = StructType::get(newFunction->getContext(), ArgTypes);
476  Struct = new AllocaInst(StructArgTy, nullptr, "structArg",
477  &codeReplacer->getParent()->front().front());
478  params.push_back(Struct);
479 
480  for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
481  Value *Idx[2];
482  Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context));
483  Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), i);
485  StructArgTy, Struct, Idx, "gep_" + StructValues[i]->getName());
486  codeReplacer->getInstList().push_back(GEP);
487  StoreInst *SI = new StoreInst(StructValues[i], GEP);
488  codeReplacer->getInstList().push_back(SI);
489  }
490  }
491 
492  // Emit the call to the function
493  CallInst *call = CallInst::Create(newFunction, params,
494  NumExitBlocks > 1 ? "targetBlock" : "");
495  codeReplacer->getInstList().push_back(call);
496 
497  Function::arg_iterator OutputArgBegin = newFunction->arg_begin();
498  unsigned FirstOut = inputs.size();
499  if (!AggregateArgs)
500  std::advance(OutputArgBegin, inputs.size());
501 
502  // Reload the outputs passed in by reference
503  for (unsigned i = 0, e = outputs.size(); i != e; ++i) {
504  Value *Output = nullptr;
505  if (AggregateArgs) {
506  Value *Idx[2];
507  Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context));
508  Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), FirstOut + i);
510  StructArgTy, Struct, Idx, "gep_reload_" + outputs[i]->getName());
511  codeReplacer->getInstList().push_back(GEP);
512  Output = GEP;
513  } else {
514  Output = ReloadOutputs[i];
515  }
516  LoadInst *load = new LoadInst(Output, outputs[i]->getName()+".reload");
517  Reloads.push_back(load);
518  codeReplacer->getInstList().push_back(load);
519  std::vector<User*> Users(outputs[i]->user_begin(), outputs[i]->user_end());
520  for (unsigned u = 0, e = Users.size(); u != e; ++u) {
521  Instruction *inst = cast<Instruction>(Users[u]);
522  if (!Blocks.count(inst->getParent()))
523  inst->replaceUsesOfWith(outputs[i], load);
524  }
525  }
526 
527  // Now we can emit a switch statement using the call as a value.
528  SwitchInst *TheSwitch =
530  codeReplacer, 0, codeReplacer);
531 
532  // Since there may be multiple exits from the original region, make the new
533  // function return an unsigned, switch on that number. This loop iterates
534  // over all of the blocks in the extracted region, updating any terminator
535  // instructions in the to-be-extracted region that branch to blocks that are
536  // not in the region to be extracted.
537  std::map<BasicBlock*, BasicBlock*> ExitBlockMap;
538 
539  unsigned switchVal = 0;
540  for (BasicBlock *Block : Blocks) {
541  TerminatorInst *TI = Block->getTerminator();
542  for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
543  if (!Blocks.count(TI->getSuccessor(i))) {
544  BasicBlock *OldTarget = TI->getSuccessor(i);
545  // add a new basic block which returns the appropriate value
546  BasicBlock *&NewTarget = ExitBlockMap[OldTarget];
547  if (!NewTarget) {
548  // If we don't already have an exit stub for this non-extracted
549  // destination, create one now!
550  NewTarget = BasicBlock::Create(Context,
551  OldTarget->getName() + ".exitStub",
552  newFunction);
553  unsigned SuccNum = switchVal++;
554 
555  Value *brVal = nullptr;
556  switch (NumExitBlocks) {
557  case 0:
558  case 1: break; // No value needed.
559  case 2: // Conditional branch, return a bool
560  brVal = ConstantInt::get(Type::getInt1Ty(Context), !SuccNum);
561  break;
562  default:
563  brVal = ConstantInt::get(Type::getInt16Ty(Context), SuccNum);
564  break;
565  }
566 
567  ReturnInst *NTRet = ReturnInst::Create(Context, brVal, NewTarget);
568 
569  // Update the switch instruction.
570  TheSwitch->addCase(ConstantInt::get(Type::getInt16Ty(Context),
571  SuccNum),
572  OldTarget);
573 
574  // Restore values just before we exit
575  Function::arg_iterator OAI = OutputArgBegin;
576  for (unsigned out = 0, e = outputs.size(); out != e; ++out) {
577  // For an invoke, the normal destination is the only one that is
578  // dominated by the result of the invocation
579  BasicBlock *DefBlock = cast<Instruction>(outputs[out])->getParent();
580 
581  bool DominatesDef = true;
582 
583  BasicBlock *NormalDest = nullptr;
584  if (auto *Invoke = dyn_cast<InvokeInst>(outputs[out]))
585  NormalDest = Invoke->getNormalDest();
586 
587  if (NormalDest) {
588  DefBlock = NormalDest;
589 
590  // Make sure we are looking at the original successor block, not
591  // at a newly inserted exit block, which won't be in the dominator
592  // info.
593  for (const auto &I : ExitBlockMap)
594  if (DefBlock == I.second) {
595  DefBlock = I.first;
596  break;
597  }
598 
599  // In the extract block case, if the block we are extracting ends
600  // with an invoke instruction, make sure that we don't emit a
601  // store of the invoke value for the unwind block.
602  if (!DT && DefBlock != OldTarget)
603  DominatesDef = false;
604  }
605 
606  if (DT) {
607  DominatesDef = DT->dominates(DefBlock, OldTarget);
608 
609  // If the output value is used by a phi in the target block,
610  // then we need to test for dominance of the phi's predecessor
611  // instead. Unfortunately, this a little complicated since we
612  // have already rewritten uses of the value to uses of the reload.
613  BasicBlock* pred = FindPhiPredForUseInBlock(Reloads[out],
614  OldTarget);
615  if (pred && DT && DT->dominates(DefBlock, pred))
616  DominatesDef = true;
617  }
618 
619  if (DominatesDef) {
620  if (AggregateArgs) {
621  Value *Idx[2];
622  Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context));
623  Idx[1] = ConstantInt::get(Type::getInt32Ty(Context),
624  FirstOut+out);
626  StructArgTy, &*OAI, Idx, "gep_" + outputs[out]->getName(),
627  NTRet);
628  new StoreInst(outputs[out], GEP, NTRet);
629  } else {
630  new StoreInst(outputs[out], &*OAI, NTRet);
631  }
632  }
633  // Advance output iterator even if we don't emit a store
634  if (!AggregateArgs) ++OAI;
635  }
636  }
637 
638  // rewrite the original branch instruction with this new target
639  TI->setSuccessor(i, NewTarget);
640  }
641  }
642 
643  // Now that we've done the deed, simplify the switch instruction.
644  Type *OldFnRetTy = TheSwitch->getParent()->getParent()->getReturnType();
645  switch (NumExitBlocks) {
646  case 0:
647  // There are no successors (the block containing the switch itself), which
648  // means that previously this was the last part of the function, and hence
649  // this should be rewritten as a `ret'
650 
651  // Check if the function should return a value
652  if (OldFnRetTy->isVoidTy()) {
653  ReturnInst::Create(Context, nullptr, TheSwitch); // Return void
654  } else if (OldFnRetTy == TheSwitch->getCondition()->getType()) {
655  // return what we have
656  ReturnInst::Create(Context, TheSwitch->getCondition(), TheSwitch);
657  } else {
658  // Otherwise we must have code extracted an unwind or something, just
659  // return whatever we want.
660  ReturnInst::Create(Context,
661  Constant::getNullValue(OldFnRetTy), TheSwitch);
662  }
663 
664  TheSwitch->eraseFromParent();
665  break;
666  case 1:
667  // Only a single destination, change the switch into an unconditional
668  // branch.
669  BranchInst::Create(TheSwitch->getSuccessor(1), TheSwitch);
670  TheSwitch->eraseFromParent();
671  break;
672  case 2:
673  BranchInst::Create(TheSwitch->getSuccessor(1), TheSwitch->getSuccessor(2),
674  call, TheSwitch);
675  TheSwitch->eraseFromParent();
676  break;
677  default:
678  // Otherwise, make the default destination of the switch instruction be one
679  // of the other successors.
680  TheSwitch->setCondition(call);
681  TheSwitch->setDefaultDest(TheSwitch->getSuccessor(NumExitBlocks));
682  // Remove redundant case
683  TheSwitch->removeCase(SwitchInst::CaseIt(TheSwitch, NumExitBlocks-1));
684  break;
685  }
686 }
687 
688 void CodeExtractor::moveCodeToFunction(Function *newFunction) {
689  Function *oldFunc = (*Blocks.begin())->getParent();
690  Function::BasicBlockListType &oldBlocks = oldFunc->getBasicBlockList();
691  Function::BasicBlockListType &newBlocks = newFunction->getBasicBlockList();
692 
693  for (BasicBlock *Block : Blocks) {
694  // Delete the basic block from the old function, and the list of blocks
695  oldBlocks.remove(Block);
696 
697  // Insert this basic block into the new function
698  newBlocks.push_back(Block);
699  }
700 }
701 
702 void CodeExtractor::calculateNewCallTerminatorWeights(
703  BasicBlock *CodeReplacer,
705  BranchProbabilityInfo *BPI) {
706  typedef BlockFrequencyInfoImplBase::Distribution Distribution;
707  typedef BlockFrequencyInfoImplBase::BlockNode BlockNode;
708 
709  // Update the branch weights for the exit block.
710  TerminatorInst *TI = CodeReplacer->getTerminator();
711  SmallVector<unsigned, 8> BranchWeights(TI->getNumSuccessors(), 0);
712 
713  // Block Frequency distribution with dummy node.
714  Distribution BranchDist;
715 
716  // Add each of the frequencies of the successors.
717  for (unsigned i = 0, e = TI->getNumSuccessors(); i < e; ++i) {
718  BlockNode ExitNode(i);
719  uint64_t ExitFreq = ExitWeights[TI->getSuccessor(i)].getFrequency();
720  if (ExitFreq != 0)
721  BranchDist.addExit(ExitNode, ExitFreq);
722  else
723  BPI->setEdgeProbability(CodeReplacer, i, BranchProbability::getZero());
724  }
725 
726  // Check for no total weight.
727  if (BranchDist.Total == 0)
728  return;
729 
730  // Normalize the distribution so that they can fit in unsigned.
731  BranchDist.normalize();
732 
733  // Create normalized branch weights and set the metadata.
734  for (unsigned I = 0, E = BranchDist.Weights.size(); I < E; ++I) {
735  const auto &Weight = BranchDist.Weights[I];
736 
737  // Get the weight and update the current BFI.
738  BranchWeights[Weight.TargetNode.Index] = Weight.Amount;
739  BranchProbability BP(Weight.Amount, BranchDist.Total);
740  BPI->setEdgeProbability(CodeReplacer, Weight.TargetNode.Index, BP);
741  }
742  TI->setMetadata(
744  MDBuilder(TI->getContext()).createBranchWeights(BranchWeights));
745 }
746 
748  if (!isEligible())
749  return nullptr;
750 
751  ValueSet inputs, outputs;
752 
753  // Assumption: this is a single-entry code region, and the header is the first
754  // block in the region.
755  BasicBlock *header = *Blocks.begin();
756 
757  // Calculate the entry frequency of the new function before we change the root
758  // block.
759  BlockFrequency EntryFreq;
760  if (BFI) {
761  assert(BPI && "Both BPI and BFI are required to preserve profile info");
762  for (BasicBlock *Pred : predecessors(header)) {
763  if (Blocks.count(Pred))
764  continue;
765  EntryFreq +=
766  BFI->getBlockFreq(Pred) * BPI->getEdgeProbability(Pred, header);
767  }
768  }
769 
770  // If we have to split PHI nodes or the entry block, do so now.
771  severSplitPHINodes(header);
772 
773  // If we have any return instructions in the region, split those blocks so
774  // that the return is not in the region.
775  splitReturnBlocks();
776 
777  Function *oldFunction = header->getParent();
778 
779  // This takes place of the original loop
780  BasicBlock *codeReplacer = BasicBlock::Create(header->getContext(),
781  "codeRepl", oldFunction,
782  header);
783 
784  // The new function needs a root node because other nodes can branch to the
785  // head of the region, but the entry node of a function cannot have preds.
786  BasicBlock *newFuncRoot = BasicBlock::Create(header->getContext(),
787  "newFuncRoot");
788  newFuncRoot->getInstList().push_back(BranchInst::Create(header));
789 
790  // Find inputs to, outputs from the code region.
791  findInputsOutputs(inputs, outputs);
792 
793  // Calculate the exit blocks for the extracted region and the total exit
794  // weights for each of those blocks.
796  SmallPtrSet<BasicBlock *, 1> ExitBlocks;
797  for (BasicBlock *Block : Blocks) {
798  for (succ_iterator SI = succ_begin(Block), SE = succ_end(Block); SI != SE;
799  ++SI) {
800  if (!Blocks.count(*SI)) {
801  // Update the branch weight for this successor.
802  if (BFI) {
803  BlockFrequency &BF = ExitWeights[*SI];
804  BF += BFI->getBlockFreq(Block) * BPI->getEdgeProbability(Block, *SI);
805  }
806  ExitBlocks.insert(*SI);
807  }
808  }
809  }
810  NumExitBlocks = ExitBlocks.size();
811 
812  // Construct new function based on inputs/outputs & add allocas for all defs.
813  Function *newFunction = constructFunction(inputs, outputs, header,
814  newFuncRoot,
815  codeReplacer, oldFunction,
816  oldFunction->getParent());
817 
818  // Update the entry count of the function.
819  if (BFI) {
820  Optional<uint64_t> EntryCount =
821  BFI->getProfileCountFromFreq(EntryFreq.getFrequency());
822  if (EntryCount.hasValue())
823  newFunction->setEntryCount(EntryCount.getValue());
824  BFI->setBlockFreq(codeReplacer, EntryFreq.getFrequency());
825  }
826 
827  emitCallAndSwitchStatement(newFunction, codeReplacer, inputs, outputs);
828 
829  moveCodeToFunction(newFunction);
830 
831  // Update the branch weights for the exit block.
832  if (BFI && NumExitBlocks > 1)
833  calculateNewCallTerminatorWeights(codeReplacer, ExitWeights, BPI);
834 
835  // Loop over all of the PHI nodes in the header block, and change any
836  // references to the old incoming edge to be the new incoming edge.
837  for (BasicBlock::iterator I = header->begin(); isa<PHINode>(I); ++I) {
838  PHINode *PN = cast<PHINode>(I);
839  for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
840  if (!Blocks.count(PN->getIncomingBlock(i)))
841  PN->setIncomingBlock(i, newFuncRoot);
842  }
843 
844  // Look at all successors of the codeReplacer block. If any of these blocks
845  // had PHI nodes in them, we need to update the "from" block to be the code
846  // replacer, not the original block in the extracted region.
847  std::vector<BasicBlock*> Succs(succ_begin(codeReplacer),
848  succ_end(codeReplacer));
849  for (unsigned i = 0, e = Succs.size(); i != e; ++i)
850  for (BasicBlock::iterator I = Succs[i]->begin(); isa<PHINode>(I); ++I) {
851  PHINode *PN = cast<PHINode>(I);
852  std::set<BasicBlock*> ProcessedPreds;
853  for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
854  if (Blocks.count(PN->getIncomingBlock(i))) {
855  if (ProcessedPreds.insert(PN->getIncomingBlock(i)).second)
856  PN->setIncomingBlock(i, codeReplacer);
857  else {
858  // There were multiple entries in the PHI for this block, now there
859  // is only one, so remove the duplicated entries.
860  PN->removeIncomingValue(i, false);
861  --i; --e;
862  }
863  }
864  }
865 
866  //cerr << "NEW FUNCTION: " << *newFunction;
867  // verifyFunction(*newFunction);
868 
869  // cerr << "OLD FUNCTION: " << *oldFunction;
870  // verifyFunction(*oldFunction);
871 
872  DEBUG(if (verifyFunction(*newFunction))
873  report_fatal_error("verifyFunction failed!"));
874  return newFunction;
875 }
MachineLoop * L
DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)
Add a new node to the dominator tree information.
Return a value (possibly void), from a function.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:76
iterator_range< use_iterator > uses()
Definition: Value.h:326
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:166
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:226
LLVMContext & Context
bool hasValue() const
Definition: Optional.h:125
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
size_t i
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:52
static cl::opt< bool > AggregateArgsOpt("aggregate-extracted-args", cl::Hidden, cl::desc("Aggregate arguments to code-extracted functions"))
void addCase(ConstantInt *OnVal, BasicBlock *Dest)
Add an entry to the switch instruction.
iterator end() const
Definition: ArrayRef.h:130
This class represents a function call, abstracting a target machine's calling convention.
Function * extractCodeRegion()
Perform the extraction, returning the new function.
const_iterator begin(StringRef path)
Get begin iterator over path.
Definition: Path.cpp:233
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.cpp:238
bool isEHPad() const
Return true if this basic block is an exception handling block.
Definition: BasicBlock.h:315
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:100
const Instruction & front() const
Definition: BasicBlock.h:240
bool isSubRegion() const
Is this RegionNode a subregion?
Definition: RegionInfo.h:183
An instruction for reading from memory.
Definition: Instructions.h:164
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
Hexagon Common GEP
iv Induction Variable Users
Definition: IVUsers.cpp:51
static IntegerType * getInt16Ty(LLVMContext &C)
Definition: Type.cpp:168
static bool isBlockValidForExtraction(const BasicBlock &BB)
Check to see if a block is valid for extraction.
iterator end()
Get an iterator to the end of the SetVector.
Definition: SetVector.h:93
T * getNodeAs() const
Get the content of this RegionNode.
static BasicBlock * FindPhiPredForUseInBlock(Value *Used, BasicBlock *BB)
FindPhiPredForUseInBlock - Given a value and a basic block, find a PHI that uses the value within the...
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Definition: Constants.cpp:195
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:191
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:228
void setDoesNotThrow()
Definition: Function.h:373
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
bool doesNotThrow() const
Determine if the function cannot unwind.
Definition: Function.h:370
Class to represent struct types.
Definition: DerivedTypes.h:199
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
static void advance(T &it, size_t Val)
Instruction * getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:180
static StringRef getName(Value *V)
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Definition: Interval.h:106
Class to represent function types.
Definition: DerivedTypes.h:102
#define F(x, y, z)
Definition: MD5.cpp:51
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:136
const T & getValue() const LLVM_LVALUE_FUNCTION
Definition: Optional.h:121
iterator begin()
Get an iterator to the beginning of the SetVector.
Definition: SetVector.h:83
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:291
Base class for the actual dominator tree node.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
void setSuccessor(unsigned idx, BasicBlock *B)
Update the specified successor to point at the provided block.
Definition: InstrTypes.h:84
An instruction for storing to memory.
Definition: Instructions.h:300
iterator begin()
Definition: Function.h:535
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:96
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
Interval::succ_iterator succ_end(Interval *I)
Definition: Interval.h:109
unsigned getNumIncomingValues() const
Return the number of incoming edges.
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
Definition: User.cpp:24
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
Definition: InstrTypes.h:74
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
Definition: Instructions.h:830
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
#define P(N)
void findInputsOutputs(ValueSet &Inputs, ValueSet &Outputs) const
Compute the set of input values and output values for the code.
Subclasses of this class are all able to terminate a basic block.
Definition: InstrTypes.h:52
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
size_type size() const
Definition: SmallPtrSet.h:99
CodeExtractor(BasicBlock *BB, bool AggregateArgs=false, BlockFrequencyInfo *BFI=nullptr, BranchProbabilityInfo *BPI=nullptr)
Create a code extractor for a single basic block.
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
Definition: InstrTypes.h:79
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Distribution of unscaled probability weight.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:368
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Definition: Interval.h:116
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:154
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
const InstListType & getInstList() const
Return the underlying instruction list container.
Definition: BasicBlock.h:249
iterator begin() const
Definition: ArrayRef.h:129
bool isEligible() const
Test whether this code extractor is eligible.
Interval::pred_iterator pred_end(Interval *I)
Definition: Interval.h:119
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:93
arg_iterator arg_begin()
Definition: Function.h:550
self_iterator getIterator()
Definition: ilist_node.h:81
void setHasUWTable()
Definition: Function.h:410
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:654
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:857
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1183
hexagon gen pred
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
Definition: Dominators.cpp:218
void setEntryCount(uint64_t Count)
Set the entry count for this function.
Definition: Function.cpp:1282
Iterator for intrusive lists based on ilist_node.
const BasicBlockListType & getBasicBlockList() const
Definition: Function.h:512
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:425
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
Definition: DerivedTypes.h:458
void setIncomingBlock(unsigned i, BasicBlock *BB)
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition: Type.cpp:330
iterator end()
Definition: BasicBlock.h:230
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, Instruction *InsertBefore=nullptr)
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:230
static bool definedInRegion(const SetVector< BasicBlock * > &Blocks, Value *V)
definedInRegion - Return true if the specified value is defined in the extracted region.
void setEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors, BranchProbability Prob)
Set the raw edge probability for the given edge.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:558
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
pred_range predecessors(BasicBlock *BB)
Definition: IR/CFG.h:110
const BasicBlock & getEntryBlock() const
Definition: Function.h:519
static bool definedInCaller(const SetVector< BasicBlock * > &Blocks, Value *V)
definedInCaller - Return true if the specified value is defined in the function being code extracted...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
AttributeSet getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:176
void clear()
Completely clear the SetVector.
Definition: SetVector.h:210
static SetVector< BasicBlock * > buildExtractionBlockSet(IteratorT BBBegin, IteratorT BBEnd)
Build a set of blocks to extract if the input blocks are viable.
void push_back(pointer val)
Definition: ilist.h:326
iterator_range< user_iterator > users()
Definition: Value.h:370
Value * getCondition() const
pointer remove(iterator &IT)
Definition: ilist.h:264
block_iterator block_begin()
Definition: RegionInfo.h:598
BasicBlock * getSuccessor(unsigned idx) const
Analysis providing branch probability information.
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
Definition: SetVector.h:205
block_iterator block_end()
Definition: RegionInfo.h:600
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:169
void setCondition(Value *V)
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:368
#define I(x, y, z)
Definition: MD5.cpp:54
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:124
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
Definition: Verifier.cpp:4430
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:287
Rename collisions when linking (static functions).
Definition: GlobalValue.h:56
bool hasUWTable() const
True if the ABI mandates (or the user requested) that this function be in a unwind table...
Definition: Function.h:407
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
Definition: BasicBlock.cpp:374
void removeCase(CaseIt i)
This method removes the specified case and its successor from the switch instruction.
pgo instr use
void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)
changeImmediateDominator - This method is used to update the dominator tree information when a node's...
Multiway switch.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
Definition: Value.h:346
const BasicBlock & front() const
Definition: Function.h:542
LLVMContext & getContext() const
Get the context in which this basic block lives.
Definition: BasicBlock.cpp:33
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:537
LLVM Value Representation.
Definition: Value.h:71
vector_type::const_iterator iterator
Definition: SetVector.h:49
void setDefaultDest(BasicBlock *DefaultCase)
A vector that has set insertion semantics.
Definition: SetVector.h:41
static const Function * getParent(const Value *V)
BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
#define DEBUG(X)
Definition: Debug.h:100
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Definition: Function.h:182
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
Definition: Function.h:117
static BranchProbability getZero()
DomTreeNodeBase< NodeT > * getNode(NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
const BasicBlock * getParent() const
Definition: Instruction.h:62
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:222
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:139
an instruction to allocate memory on the stack
Definition: Instructions.h:60
void splitBlock(NodeT *NewBB)
splitBlock - BB is split and now it has one successor.
AttributeSet getFnAttributes() const
The function attributes are returned.
Definition: Attributes.cpp:985
user_iterator user_end()
Definition: Value.h:354