LLVM 24.0.0git
IRNormalizer.cpp
Go to the documentation of this file.
1//===--------------- IRNormalizer.cpp - IR Normalizer ---------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// This file implements the IRNormalizer class which aims to transform LLVM
10/// Modules into a normal form by reordering and renaming instructions while
11/// preserving the same semantics. The normalizer makes it easier to spot
12/// semantic differences while diffing two modules which have undergone
13/// different passes.
14///
15//===----------------------------------------------------------------------===//
16
18#include "llvm/ADT/SetVector.h"
23#include "llvm/IR/BasicBlock.h"
24#include "llvm/IR/Function.h"
25#include "llvm/IR/IRBuilder.h"
27#include "llvm/Pass.h"
28#include <stack>
29
30#define DEBUG_TYPE "normalize"
31
32using namespace llvm;
33
34// Frozen mixer; basic-block names derived from these hashes appear in
35// the normalized IR text and must be deterministic across processes
36// for the normalizer's "compare normalized IR" workflow to work.
37static constexpr uint64_t hash_16_bytes(uint64_t low, uint64_t high) {
38 const uint64_t kMul = 0x9ddfea08eb382d69ULL;
39 uint64_t a = (low ^ high) * kMul;
40 a ^= (a >> 47);
41 uint64_t b = (high ^ a) * kMul;
42 b ^= (b >> 47);
43 b *= kMul;
44 return b;
45}
46
47namespace {
48/// IRNormalizer aims to transform LLVM IR into normal form.
49class IRNormalizer {
50public:
52
53 IRNormalizer(IRNormalizerOptions Options) : Options(Options) {}
54
55private:
56 const IRNormalizerOptions Options;
57
58 // Random constant for hashing, so the state isn't zero.
59 const uint64_t MagicHashConstant = 0x6acaa36bef8325c5ULL;
60 DenseSet<const Instruction *> NamedInstructions;
61
62 SmallVector<Instruction *, 16> Outputs;
63
64 /// \name Naming.
65 /// @{
66 void nameFunctionArguments(Function &F) const;
67 void nameBasicBlocks(Function &F) const;
68 void nameInstruction(Instruction *I);
69 void nameAsInitialInstruction(Instruction *I) const;
70 void nameAsRegularInstruction(Instruction *I);
71 void foldInstructionName(Instruction *I) const;
72 /// @}
73
74 /// \name Reordering.
75 /// @{
76 void reorderInstructions(Function &F) const;
77 void reorderDefinition(Instruction *Definition,
78 std::stack<Instruction *> &TopologicalSort,
79 SmallPtrSet<const Instruction *, 32> &Visited) const;
80 void reorderInstructionOperandsByNames(Instruction *I) const;
81 void reorderPHIIncomingValues(PHINode *Phi) const;
82 /// @}
83
84 /// \name Utility methods.
85 /// @{
86 template <typename T>
87 void sortCommutativeOperands(Instruction *I, T &Operands) const;
88 SmallVector<Instruction *, 16> collectOutputInstructions(Function &F) const;
89 bool isOutput(const Instruction *I) const;
90 bool isInitialInstruction(const Instruction *I) const;
91 bool hasOnlyImmediateOperands(const Instruction *I) const;
92 SetVector<int>
93 getOutputFootprint(Instruction *I,
94 SmallPtrSet<const Instruction *, 32> &Visited) const;
95 /// @}
96};
97} // namespace
98
99/// Entry method to the IRNormalizer.
100///
101/// \param F Function to normalize.
102bool IRNormalizer::runOnFunction(Function &F) {
103 nameFunctionArguments(F);
104 nameBasicBlocks(F);
105
106 Outputs = collectOutputInstructions(F);
107
108 if (!Options.PreserveOrder)
109 reorderInstructions(F);
110
111 // TODO: Reorder basic blocks via a topological sort.
112
113 for (auto &I : Outputs)
114 nameInstruction(I);
115
116 for (auto &I : instructions(F)) {
117 if (!Options.PreserveOrder) {
118 if (Options.ReorderOperands)
119 reorderInstructionOperandsByNames(&I);
120
121 if (auto *Phi = dyn_cast<PHINode>(&I))
122 reorderPHIIncomingValues(Phi);
123 }
124 foldInstructionName(&I);
125 }
126
127 return true;
128}
129
130/// Numbers arguments.
131///
132/// \param F Function whose arguments will be renamed.
133void IRNormalizer::nameFunctionArguments(Function &F) const {
134 int ArgumentCounter = 0;
135 for (auto &A : F.args()) {
136 if (Options.RenameAll || A.getName().empty()) {
137 A.setName("a" + Twine(ArgumentCounter));
138 ArgumentCounter += 1;
139 }
140 }
141}
142
143/// Names basic blocks using a generated hash for each basic block in
144/// a function considering the opcode and the order of output instructions.
145///
146/// \param F Function containing basic blocks to rename.
147void IRNormalizer::nameBasicBlocks(Function &F) const {
148 for (auto &B : F) {
149 // Initialize to a magic constant, so the state isn't zero.
150 uint64_t Hash = MagicHashConstant;
151
152 // Hash considering output instruction opcodes.
153 for (auto &I : B)
154 if (isOutput(&I))
155 Hash = hash_16_bytes(Hash, I.getOpcode());
156
157 if (Options.RenameAll || B.getName().empty()) {
158 // Name basic block. Substring hash to make diffs more readable.
159 B.setName("bb" + std::to_string(Hash).substr(0, 5));
160 }
161 }
162}
163
164/// Names instructions graphically (recursive) in accordance with the
165/// def-use tree, starting from the initial instructions (defs), finishing at
166/// the output (top-most user) instructions (depth-first).
167///
168/// \param I Instruction to be renamed.
169void IRNormalizer::nameInstruction(Instruction *I) {
170 // Ensure instructions are not renamed. This is done
171 // to prevent situation where instructions are used
172 // before their definition (in phi nodes)
173 if (NamedInstructions.contains(I))
174 return;
175 NamedInstructions.insert(I);
176 if (isInitialInstruction(I)) {
177 nameAsInitialInstruction(I);
178 } else {
179 // This must be a regular instruction.
180 nameAsRegularInstruction(I);
181 }
182}
183
184template <typename T>
185void IRNormalizer::sortCommutativeOperands(Instruction *I, T &Operands) const {
186 if (!(I->isCommutative() && Operands.size() >= 2))
187 return;
188 auto CommutativeEnd = Operands.begin();
189 std::advance(CommutativeEnd, 2);
190 llvm::sort(Operands.begin(), CommutativeEnd);
191}
192
193/// Names instruction following the scheme:
194/// vl00000Callee(Operands)
195///
196/// Where 00000 is a hash calculated considering instruction's opcode and output
197/// footprint. Callee's name is only included when instruction's type is
198/// CallInst. In cases where instruction is commutative, operands list is also
199/// sorted.
200///
201/// Renames instruction only when RenameAll flag is raised or instruction is
202/// unnamed.
203///
204/// \see getOutputFootprint()
205/// \param I Instruction to be renamed.
206void IRNormalizer::nameAsInitialInstruction(Instruction *I) const {
207 if (I->getType()->isVoidTy())
208 return;
209 if (!(I->getName().empty() || Options.RenameAll))
210 return;
211 LLVM_DEBUG(dbgs() << "Naming initial instruction: " << *I << "\n");
212
213 // Instruction operands for further sorting.
215
216 // Collect operands.
217 for (auto &Op : I->operands()) {
218 if (!isa<Function>(Op)) {
219 std::string TextRepresentation;
220 raw_string_ostream Stream(TextRepresentation);
221 Op->printAsOperand(Stream, false);
222 Operands.push_back(StringRef(Stream.str()));
223 }
224 }
225
226 sortCommutativeOperands(I, Operands);
227
228 // Initialize to a magic constant, so the state isn't zero.
229 uint64_t Hash = MagicHashConstant;
230
231 // Consider instruction's opcode in the hash.
232 Hash = hash_16_bytes(Hash, I->getOpcode());
233
234 SmallPtrSet<const Instruction *, 32> Visited;
235 // Get output footprint for I.
236 SetVector<int> OutputFootprint = getOutputFootprint(I, Visited);
237
238 // Consider output footprint in the hash.
239 for (const int &Output : OutputFootprint)
240 Hash = hash_16_bytes(Hash, Output);
241
242 // Base instruction name.
243 SmallString<256> Name;
244 Name.append("vl" + std::to_string(Hash).substr(0, 5));
245
246 // In case of CallInst, consider callee in the instruction name.
247 if (const auto *CI = dyn_cast<CallInst>(I)) {
248 Function *F = CI->getCalledFunction();
249
250 if (F != nullptr)
251 Name.append(F->getName());
252 }
253
254 Name.append("(");
255 for (size_t i = 0; i < Operands.size(); ++i) {
256 Name.append(Operands[i]);
257
258 if (i < Operands.size() - 1)
259 Name.append(", ");
260 }
261 Name.append(")");
262
263 I->setName(Name);
264}
265
266/// Names instruction following the scheme:
267/// op00000Callee(Operands)
268///
269/// Where 00000 is a hash calculated considering instruction's opcode, its
270/// operands' opcodes and order. Callee's name is only included when
271/// instruction's type is CallInst. In cases where instruction is commutative,
272/// operand list is also sorted.
273///
274/// Names instructions recursively in accordance with the def-use tree,
275/// starting from the initial instructions (defs), finishing at
276/// the output (top-most user) instructions (depth-first).
277///
278/// Renames instruction only when RenameAll flag is raised or instruction is
279/// unnamed.
280///
281/// \see getOutputFootprint()
282/// \param I Instruction to be renamed.
283void IRNormalizer::nameAsRegularInstruction(Instruction *I) {
284 LLVM_DEBUG(dbgs() << "Naming regular instruction: " << *I << "\n");
285
286 // Instruction operands for further sorting.
288
289 // The name of a regular instruction depends
290 // on the names of its operands. Hence, all
291 // operands must be named first in the use-def
292 // walk.
293
294 // Collect operands.
295 for (auto &Op : I->operands()) {
296 if (auto *I = dyn_cast<Instruction>(Op)) {
297 // Walk down the use-def chain.
298 nameInstruction(I);
299 Operands.push_back(I->getName());
300 } else if (!isa<Function>(Op)) {
301 // This must be an immediate value.
302 std::string TextRepresentation;
303 raw_string_ostream Stream(TextRepresentation);
304 Op->printAsOperand(Stream, false);
305 Operands.push_back(StringRef(Stream.str()));
306 }
307 }
308
309 sortCommutativeOperands(I, Operands);
310
311 // Initialize to a magic constant, so the state isn't zero.
312 uint64_t Hash = MagicHashConstant;
313
314 // Consider instruction opcode in the hash.
315 Hash = hash_16_bytes(Hash, I->getOpcode());
316
317 // Operand opcodes for further sorting (commutative).
318 SmallVector<int, 4> OperandsOpcodes;
319
320 // Collect operand opcodes for hashing.
321 for (auto &Op : I->operands())
322 if (auto *I = dyn_cast<Instruction>(Op))
323 OperandsOpcodes.push_back(I->getOpcode());
324
325 sortCommutativeOperands(I, OperandsOpcodes);
326
327 // Consider operand opcodes in the hash.
328 for (const int Code : OperandsOpcodes)
329 Hash = hash_16_bytes(Hash, Code);
330
331 // Base instruction name.
332 SmallString<512> Name;
333 Name.append("op" + std::to_string(Hash).substr(0, 5));
334
335 // In case of CallInst, consider callee in the instruction name.
336 if (const auto *CI = dyn_cast<CallInst>(I))
337 if (const Function *F = CI->getCalledFunction())
338 Name.append(F->getName());
339
340 Name.append("(");
341 for (size_t i = 0; i < Operands.size(); ++i) {
342 Name.append(Operands[i]);
343
344 if (i < Operands.size() - 1)
345 Name.append(", ");
346 }
347 Name.append(")");
348
349 if ((I->getName().empty() || Options.RenameAll) && !I->getType()->isVoidTy())
350 I->setName(Name);
351}
352
353/// Shortens instruction's name. This method removes called function name from
354/// the instruction name and substitutes the call chain with a corresponding
355/// list of operands.
356///
357/// Examples:
358/// op00000Callee(op00001Callee(...), vl00000Callee(1, 2), ...) ->
359/// op00000(op00001, vl00000, ...) vl00000Callee(1, 2) -> vl00000(1, 2)
360///
361/// This method omits output instructions and pre-output (instructions directly
362/// used by an output instruction) instructions (by default). By default it also
363/// does not affect user named instructions.
364///
365/// \param I Instruction whose name will be folded.
366void IRNormalizer::foldInstructionName(Instruction *I) const {
367 // If this flag is raised, fold all regular
368 // instructions (including pre-outputs).
369 if (!Options.FoldPreOutputs) {
370 // Don't fold if one of the users is an output instruction.
371 for (Instruction *IU : I->users())
372 if (isOutput(IU))
373 return;
374 }
375
376 // Don't fold if it is an output instruction or has no op prefix.
377 if (isOutput(I) || !I->getName().starts_with("op"))
378 return;
379
380 // Instruction operands.
382
383 for (auto &Op : I->operands()) {
384 if (const auto *I = dyn_cast<Instruction>(Op)) {
385 bool HasNormalName =
386 I->getName().starts_with("op") || I->getName().starts_with("vl");
387
388 Operands.push_back(HasNormalName ? I->getName().substr(0, 7)
389 : I->getName());
390 }
391 }
392
393 sortCommutativeOperands(I, Operands);
394
395 SmallString<256> Name;
396 Name.append(I->getName().substr(0, 7));
397
398 Name.append("(");
399 for (size_t i = 0; i < Operands.size(); ++i) {
400 Name.append(Operands[i]);
401
402 if (i < Operands.size() - 1)
403 Name.append(", ");
404 }
405 Name.append(")");
406
407 I->setName(Name);
408}
409
410/// Reorders the instructions in each basic block. Allocas, instructions that
411/// access memory or have side effects, and terminators are visited from first
412/// to last, so they keep their relative order. Each one first pulls in the
413/// operands it needs, so other instructions move down to just before their
414/// first user in the block, or to the end of the block if they have none.
415///
416/// \see reorderDefinition()
417void IRNormalizer::reorderInstructions(Function &F) const {
418 for (auto &BB : F) {
419 LLVM_DEBUG(dbgs() << "Reordering instructions in basic block: "
420 << BB.getName() << "\n");
421 // Find the source nodes of the DAG of instructions in this basic block.
422 // Source nodes are allocas, instructions that access memory, have side
423 // effects, are terminators, or don't have a parent in the DAG of
424 // instructions.
425 //
426 // We must iterate from the first to the last instruction to preserve the
427 // order of memory accesses and other side effects. SSA operand dependencies
428 // alone do not prevent a read from moving past a write to the same memory,
429 // or an alloca from moving past an llvm.stacksave or llvm.stackrestore,
430 // which would change its lifetime.
431
432 std::stack<Instruction *> TopologicalSort;
433 SmallPtrSet<const Instruction *, 32> Visited;
434 for (auto &I : BB) {
435 // First process allocas and memory accessing, side effecting and
436 // terminating instructions.
437 if (!(isOutput(&I) || I.mayReadOrWriteMemory() || I.isTerminator() ||
439 continue;
440 LLVM_DEBUG(dbgs() << "\tReordering from source effecting instruction: ";
441 I.dump());
442 reorderDefinition(&I, TopologicalSort, Visited);
443 }
444
445 for (auto &I : BB) {
446 // Process the remaining instructions.
447 //
448 // TODO: Do more a intelligent sorting of these instructions. For example,
449 // separate between dead instructions and instructions used in another
450 // block. Use properties of the CFG the order instructions that are used
451 // in another block.
452 if (Visited.contains(&I))
453 continue;
454 LLVM_DEBUG(dbgs() << "\tReordering from source instruction: "; I.dump());
455 reorderDefinition(&I, TopologicalSort, Visited);
456 }
457
458 LLVM_DEBUG(dbgs() << "Inserting instructions into: " << BB.getName()
459 << "\n");
460 // Reorder based on the topological sort.
461 while (!TopologicalSort.empty()) {
462 auto *Instruction = TopologicalSort.top();
463 auto FirstNonPHIOrAlloca = BB.getFirstNonPHIOrAlloca();
464 if (auto *Call = dyn_cast<CallInst>(&*FirstNonPHIOrAlloca)) {
465 if (Call->getIntrinsicID() ==
466 Intrinsic::experimental_convergence_entry ||
467 Call->getIntrinsicID() == Intrinsic::experimental_convergence_loop)
468 FirstNonPHIOrAlloca++;
469 }
470 Instruction->moveBefore(FirstNonPHIOrAlloca);
471 TopologicalSort.pop();
472 }
473 }
474}
475
476void IRNormalizer::reorderDefinition(
477 Instruction *Definition, std::stack<Instruction *> &TopologicalSort,
478 SmallPtrSet<const Instruction *, 32> &Visited) const {
479 if (Visited.contains(Definition))
480 return;
481 Visited.insert(Definition);
482
483 {
484 const auto *BasicBlock = Definition->getParent();
485 const auto FirstNonPHIOrAlloca = BasicBlock->getFirstNonPHIOrAlloca();
486 if (FirstNonPHIOrAlloca == BasicBlock->end())
487 return; // TODO: Is this necessary?
488 if (Definition->comesBefore(&*FirstNonPHIOrAlloca))
489 return; // TODO: Do some kind of ordering for these instructions.
490 }
491
492 for (auto &Operand : Definition->operands()) {
493 if (auto *Op = dyn_cast<Instruction>(Operand)) {
494 if (Op->getParent() != Definition->getParent())
495 continue; // Only reorder instruction within the same basic block
496 reorderDefinition(Op, TopologicalSort, Visited);
497 }
498 }
499
500 LLVM_DEBUG(dbgs() << "\t\tNext in topological sort: "; Definition->dump());
501 if (Definition->isTerminator())
502 return;
503 if (auto *Call = dyn_cast<CallInst>(Definition)) {
504 if (Call->isMustTailCall())
505 return;
506 if (Call->getIntrinsicID() == Intrinsic::experimental_deoptimize)
507 return;
508 if (Call->getIntrinsicID() == Intrinsic::experimental_convergence_entry)
509 return;
510 if (Call->getIntrinsicID() == Intrinsic::experimental_convergence_loop)
511 return;
512 }
513 if (auto *BitCast = dyn_cast<BitCastInst>(Definition)) {
514 if (auto *Call = dyn_cast<CallInst>(BitCast->getOperand(0))) {
515 if (Call->isMustTailCall())
516 return;
517 }
518 }
519
520 TopologicalSort.emplace(Definition);
521}
522
523/// Reorders instruction's operands alphabetically. This method assumes
524/// that passed instruction is commutative. Changing the operand order
525/// in other instructions may change the semantics.
526///
527/// \param I Instruction whose operands will be reordered.
528void IRNormalizer::reorderInstructionOperandsByNames(Instruction *I) const {
529 // This method assumes that passed I is commutative,
530 // changing the order of operands in other instructions
531 // may change the semantics.
532
533 // Instruction operands for further sorting.
535
536 // Collect operands.
537 for (auto &Op : I->operands()) {
538 if (auto *V = dyn_cast<Value>(Op)) {
539 if (isa<Instruction>(V)) {
540 // This is an an instruction.
541 Operands.push_back(std::pair<std::string, Value *>(V->getName(), V));
542 } else {
543 std::string TextRepresentation;
544 raw_string_ostream Stream(TextRepresentation);
545 Op->printAsOperand(Stream, false);
546 Operands.push_back(std::pair<std::string, Value *>(Stream.str(), V));
547 }
548 }
549 }
550
551 // Sort operands.
552 sortCommutativeOperands(I, Operands);
553
554 // Reorder operands.
555 unsigned Position = 0;
556 for (auto &Op : I->operands()) {
557 Op.set(Operands[Position].second);
558 Position += 1;
559 }
560}
561
562/// Reorders PHI node's values according to the names of corresponding basic
563/// blocks.
564///
565/// \param Phi PHI node to normalize.
566void IRNormalizer::reorderPHIIncomingValues(PHINode *Phi) const {
567 // Values for further sorting.
569
570 // Collect blocks and corresponding values.
571 for (auto &BB : Phi->blocks()) {
572 Value *V = Phi->getIncomingValueForBlock(BB);
573 Values.push_back(std::pair<Value *, BasicBlock *>(V, BB));
574 }
575
576 // Sort values according to the name of a basic block.
577 llvm::sort(Values, [](const std::pair<Value *, BasicBlock *> &LHS,
578 const std::pair<Value *, BasicBlock *> &RHS) {
579 return LHS.second->getName() < RHS.second->getName();
580 });
581
582 // Swap.
583 for (unsigned i = 0; i < Values.size(); ++i) {
584 Phi->setIncomingBlock(i, Values[i].second);
585 Phi->setIncomingValue(i, Values[i].first);
586 }
587}
588
589/// Returns a vector of output instructions. An output is an instruction which
590/// has side-effects or is ReturnInst. Uses isOutput().
591///
592/// \see isOutput()
593/// \param F Function to collect outputs from.
594SmallVector<Instruction *, 16>
595IRNormalizer::collectOutputInstructions(Function &F) const {
596 // Output instructions are collected top-down in each function,
597 // any change may break the def-use chain in reordering methods.
598 SmallVector<Instruction *, 16> Outputs;
599 for (auto &I : instructions(F))
600 if (isOutput(&I))
601 Outputs.push_back(&I);
602 return Outputs;
603}
604
605/// Helper method checking whether the instruction may have side effects or is
606/// ReturnInst.
607///
608/// \param I Considered instruction.
609bool IRNormalizer::isOutput(const Instruction *I) const {
610 // Outputs are such instructions which may have side effects or is ReturnInst.
611 return I->mayHaveSideEffects() || isa<ReturnInst>(I);
612}
613
614/// Helper method checking whether the instruction has users and only
615/// immediate operands.
616///
617/// \param I Considered instruction.
618bool IRNormalizer::isInitialInstruction(const Instruction *I) const {
619 // Initial instructions are such instructions whose values are used by
620 // other instructions, yet they only depend on immediate values.
621 return !I->user_empty() && hasOnlyImmediateOperands(I);
622}
623
624/// Helper method checking whether the instruction has only immediate operands.
625///
626/// \param I Considered instruction.
627bool IRNormalizer::hasOnlyImmediateOperands(const Instruction *I) const {
628 for (const auto &Op : I->operands())
629 if (isa<Instruction>(Op))
630 return false; // Found non-immediate operand (instruction).
631 return true;
632}
633
634/// Helper method returning indices (distance from the beginning of the basic
635/// block) of outputs using the \p I (eliminates repetitions). Walks down the
636/// def-use tree recursively.
637///
638/// \param I Considered instruction.
639/// \param Visited Set of visited instructions.
640SetVector<int> IRNormalizer::getOutputFootprint(
641 Instruction *I, SmallPtrSet<const Instruction *, 32> &Visited) const {
642
643 // Vector containing indexes of outputs (no repetitions),
644 // which use I in the order of walking down the def-use tree.
645 SetVector<int> Outputs;
646
647 if (!Visited.count(I)) {
648 Visited.insert(I);
649
650 if (isOutput(I)) {
651 // Gets output instruction's parent function.
652 Function *Func = I->getParent()->getParent();
653
654 // Finds and inserts the index of the output to the vector.
655 unsigned Count = 0;
656 for (const auto &B : *Func) {
657 for (const auto &E : B) {
658 if (&E == I)
659 Outputs.insert(Count);
660 Count += 1;
661 }
662 }
663
664 // Returns to the used instruction.
665 return Outputs;
666 }
667
668 for (Instruction *UI : I->users()) {
669 // Vector for outputs which use UI.
670 SetVector<int> OutputsUsingUI = getOutputFootprint(UI, Visited);
671 // Insert the indexes of outputs using UI.
672 Outputs.insert_range(OutputsUsingUI);
673 }
674 }
675
676 // Return to the used instruction.
677 return Outputs;
678}
679
681 raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
682 static_cast<PassInfoMixin<IRNormalizerPass> *>(this)->printPipeline(
683 OS, MapClassName2PassName);
684 // Print only the options that differ from the defaults.
685 const IRNormalizerOptions Defaults{};
686 SmallString<64> Params;
687 raw_svector_ostream ParamsOS(Params);
688 ListSeparator LS(";");
689 auto PrintParam = [&](StringRef Name, bool Value, bool Default) {
690 if (Value != Default)
691 ParamsOS << LS << (Value ? "" : "no-") << Name;
692 };
693 PrintParam("preserve-order", Options.PreserveOrder, Defaults.PreserveOrder);
694 PrintParam("rename-all", Options.RenameAll, Defaults.RenameAll);
695 PrintParam("fold-all", Options.FoldPreOutputs, Defaults.FoldPreOutputs);
696 PrintParam("reorder-operands", Options.ReorderOperands,
697 Defaults.ReorderOperands);
698 if (!Params.empty())
699 OS << '<' << Params << '>';
700}
701
703 FunctionAnalysisManager &AM) const {
704 IRNormalizer(Options).runOnFunction(F);
707 return PA;
708}
uint64_t uint64_t
Expand Atomic instructions
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static bool runOnFunction(Function &F, bool PostInlining)
static constexpr uint64_t hash_16_bytes(uint64_t low, uint64_t high)
static LVOptions Options
Definition LVOptions.cpp:25
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
static constexpr uint64_t hash_16_bytes(uint64_t low, uint64_t high)
#define T
SI Fold Operands
This file implements a set that has insertion order iteration characteristics.
static StringRef substr(StringRef Str, uint64_t Len)
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
#define LLVM_DEBUG(...)
Definition Debug.h:119
Value * RHS
Value * LHS
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
LLVM_ABI Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
bool isMustTailCall() const
A helper class to return the specified delimiter string after the first invocation of operator String...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
void insert_range(Range &&R)
Definition SetVector.h:182
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:157
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:28
void push_back(const T &Elt)
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:314
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
A raw_ostream that writes to an SmallVector or SmallString.
CallInst * Call
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:83
NodeAddr< PhiNode * > Phi
Definition RDFGraph.h:390
NodeAddr< FuncNode * > Func
Definition RDFGraph.h:393
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr Values
Definition InstrProf.h:91
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1652
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
DWARFExpression::Operation Op
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
bool RenameAll
Renames all instructions (including user-named)
bool ReorderOperands
Sorts and reorders operands in commutative instructions.
bool PreserveOrder
Preserves original instruction order.
bool FoldPreOutputs
Folds all regular instructions (including pre-outputs)
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) const
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)