annotate lib/IR/Instruction.cpp @ 134:3a76565eade5 LLVM5.0.1

update 5.0.1
author mir3636
date Sat, 17 Feb 2018 09:57:20 +0900
parents 803732b1fca8
children c2174574ed3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 //===-- Instruction.cpp - Implement the Instruction class -----------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 // This file implements the Instruction class for the IR library.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
14 #include "llvm/IR/Instruction.h"
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
15 #include "llvm/ADT/DenseSet.h"
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 #include "llvm/IR/Constants.h"
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 #include "llvm/IR/Instructions.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
18 #include "llvm/IR/MDBuilder.h"
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 #include "llvm/IR/Operator.h"
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #include "llvm/IR/Type.h"
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 using namespace llvm;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 Instruction *InsertBefore)
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
25 : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 // If requested, insert this instruction into a basic block...
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 if (InsertBefore) {
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
29 BasicBlock *BB = InsertBefore->getParent();
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
30 assert(BB && "Instruction to insert before is not in a basic block!");
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
31 BB->getInstList().insert(InsertBefore->getIterator(), this);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 BasicBlock *InsertAtEnd)
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
37 : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 // append this instruction into the basic block
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 assert(InsertAtEnd && "Basic block to append to may not be NULL!");
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 InsertAtEnd->getInstList().push_back(this);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 Instruction::~Instruction() {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
45 assert(!Parent && "Instruction still linked in the program!");
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 if (hasMetadataHashEntry())
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 clearMetadataHashEntries();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 void Instruction::setParent(BasicBlock *P) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 Parent = P;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
55 const Module *Instruction::getModule() const {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
56 return getParent()->getModule();
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
57 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
58
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
59 const Function *Instruction::getFunction() const {
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
60 return getParent()->getParent();
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
61 }
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
62
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
63 void Instruction::removeFromParent() {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
64 getParent()->getInstList().remove(getIterator());
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
65 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
66
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
67 iplist<Instruction>::iterator Instruction::eraseFromParent() {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
68 return getParent()->getInstList().erase(getIterator());
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
71 /// Insert an unlinked instruction into a basic block immediately before the
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
72 /// specified instruction.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 void Instruction::insertBefore(Instruction *InsertPos) {
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
74 InsertPos->getParent()->getInstList().insert(InsertPos->getIterator(), this);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
77 /// Insert an unlinked instruction into a basic block immediately after the
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
78 /// specified instruction.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 void Instruction::insertAfter(Instruction *InsertPos) {
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
80 InsertPos->getParent()->getInstList().insertAfter(InsertPos->getIterator(),
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
81 this);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
84 /// Unlink this instruction from its current basic block and insert it into the
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
85 /// basic block that MovePos lives in, right before MovePos.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 void Instruction::moveBefore(Instruction *MovePos) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
87 moveBefore(*MovePos->getParent(), MovePos->getIterator());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
88 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
89
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
90 void Instruction::moveAfter(Instruction *MovePos) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
91 moveBefore(*MovePos->getParent(), ++MovePos->getIterator());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
92 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
93
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
94 void Instruction::moveBefore(BasicBlock &BB,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
95 SymbolTableList<Instruction>::iterator I) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
96 assert(I == BB.end() || I->getParent() == &BB);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
97 BB.getInstList().splice(I, getParent()->getInstList(), getIterator());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
98 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
99
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
100 void Instruction::setHasNoUnsignedWrap(bool b) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
101 cast<OverflowingBinaryOperator>(this)->setHasNoUnsignedWrap(b);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
102 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
103
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
104 void Instruction::setHasNoSignedWrap(bool b) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
105 cast<OverflowingBinaryOperator>(this)->setHasNoSignedWrap(b);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
108 void Instruction::setIsExact(bool b) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
109 cast<PossiblyExactOperator>(this)->setIsExact(b);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
110 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
111
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
112 bool Instruction::hasNoUnsignedWrap() const {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
113 return cast<OverflowingBinaryOperator>(this)->hasNoUnsignedWrap();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
114 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
115
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
116 bool Instruction::hasNoSignedWrap() const {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
117 return cast<OverflowingBinaryOperator>(this)->hasNoSignedWrap();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
118 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
119
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
120 void Instruction::dropPoisonGeneratingFlags() {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
121 switch (getOpcode()) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
122 case Instruction::Add:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
123 case Instruction::Sub:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
124 case Instruction::Mul:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
125 case Instruction::Shl:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
126 cast<OverflowingBinaryOperator>(this)->setHasNoUnsignedWrap(false);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
127 cast<OverflowingBinaryOperator>(this)->setHasNoSignedWrap(false);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
128 break;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
129
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
130 case Instruction::UDiv:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
131 case Instruction::SDiv:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
132 case Instruction::AShr:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
133 case Instruction::LShr:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
134 cast<PossiblyExactOperator>(this)->setIsExact(false);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
135 break;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
136
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
137 case Instruction::GetElementPtr:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
138 cast<GetElementPtrInst>(this)->setIsInBounds(false);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
139 break;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
140 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
141 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
142
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
143 bool Instruction::isExact() const {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
144 return cast<PossiblyExactOperator>(this)->isExact();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
145 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
146
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
147 void Instruction::setFast(bool B) {
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
149 cast<FPMathOperator>(this)->setFast(B);
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
150 }
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
151
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
152 void Instruction::setHasAllowReassoc(bool B) {
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
153 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
154 cast<FPMathOperator>(this)->setHasAllowReassoc(B);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 void Instruction::setHasNoNaNs(bool B) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 cast<FPMathOperator>(this)->setHasNoNaNs(B);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 void Instruction::setHasNoInfs(bool B) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 cast<FPMathOperator>(this)->setHasNoInfs(B);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 void Instruction::setHasNoSignedZeros(bool B) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 cast<FPMathOperator>(this)->setHasNoSignedZeros(B);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 void Instruction::setHasAllowReciprocal(bool B) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 cast<FPMathOperator>(this)->setHasAllowReciprocal(B);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
177 void Instruction::setHasApproxFunc(bool B) {
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
178 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
179 cast<FPMathOperator>(this)->setHasApproxFunc(B);
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
180 }
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
181
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 void Instruction::setFastMathFlags(FastMathFlags FMF) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 cast<FPMathOperator>(this)->setFastMathFlags(FMF);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
187 void Instruction::copyFastMathFlags(FastMathFlags FMF) {
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
188 assert(isa<FPMathOperator>(this) && "copying fast-math flag on invalid op");
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
189 cast<FPMathOperator>(this)->copyFastMathFlags(FMF);
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
190 }
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
191
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
192 bool Instruction::isFast() const {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
193 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
194 return cast<FPMathOperator>(this)->isFast();
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
195 }
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
196
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
197 bool Instruction::hasAllowReassoc() const {
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
198 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
199 return cast<FPMathOperator>(this)->hasAllowReassoc();
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 bool Instruction::hasNoNaNs() const {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
203 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 return cast<FPMathOperator>(this)->hasNoNaNs();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 bool Instruction::hasNoInfs() const {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
208 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 return cast<FPMathOperator>(this)->hasNoInfs();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 bool Instruction::hasNoSignedZeros() const {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
213 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 return cast<FPMathOperator>(this)->hasNoSignedZeros();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 bool Instruction::hasAllowReciprocal() const {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
218 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 return cast<FPMathOperator>(this)->hasAllowReciprocal();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
222 bool Instruction::hasAllowContract() const {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
223 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
224 return cast<FPMathOperator>(this)->hasAllowContract();
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
225 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
226
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
227 bool Instruction::hasApproxFunc() const {
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
228 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
229 return cast<FPMathOperator>(this)->hasApproxFunc();
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
230 }
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
231
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 FastMathFlags Instruction::getFastMathFlags() const {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
233 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 return cast<FPMathOperator>(this)->getFastMathFlags();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 void Instruction::copyFastMathFlags(const Instruction *I) {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
238 copyFastMathFlags(I->getFastMathFlags());
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
241 void Instruction::copyIRFlags(const Value *V, bool IncludeWrapFlags) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
242 // Copy the wrapping flags.
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
243 if (IncludeWrapFlags && isa<OverflowingBinaryOperator>(this)) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
244 if (auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
245 setHasNoSignedWrap(OB->hasNoSignedWrap());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
246 setHasNoUnsignedWrap(OB->hasNoUnsignedWrap());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
247 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
248 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
249
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
250 // Copy the exact flag.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
251 if (auto *PE = dyn_cast<PossiblyExactOperator>(V))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
252 if (isa<PossiblyExactOperator>(this))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
253 setIsExact(PE->isExact());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
254
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
255 // Copy the fast-math flags.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
256 if (auto *FP = dyn_cast<FPMathOperator>(V))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
257 if (isa<FPMathOperator>(this))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
258 copyFastMathFlags(FP->getFastMathFlags());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
259
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
260 if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
261 if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
262 DestGEP->setIsInBounds(SrcGEP->isInBounds() | DestGEP->isInBounds());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
263 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
264
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
265 void Instruction::andIRFlags(const Value *V) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
266 if (auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
267 if (isa<OverflowingBinaryOperator>(this)) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
268 setHasNoSignedWrap(hasNoSignedWrap() & OB->hasNoSignedWrap());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
269 setHasNoUnsignedWrap(hasNoUnsignedWrap() & OB->hasNoUnsignedWrap());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
270 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
271 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
272
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
273 if (auto *PE = dyn_cast<PossiblyExactOperator>(V))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
274 if (isa<PossiblyExactOperator>(this))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
275 setIsExact(isExact() & PE->isExact());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
276
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
277 if (auto *FP = dyn_cast<FPMathOperator>(V)) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
278 if (isa<FPMathOperator>(this)) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
279 FastMathFlags FM = getFastMathFlags();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
280 FM &= FP->getFastMathFlags();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
281 copyFastMathFlags(FM);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
282 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
283 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
284
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
285 if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
286 if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
287 DestGEP->setIsInBounds(SrcGEP->isInBounds() & DestGEP->isInBounds());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
288 }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 const char *Instruction::getOpcodeName(unsigned OpCode) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 switch (OpCode) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 // Terminators
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 case Ret: return "ret";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 case Br: return "br";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 case Switch: return "switch";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 case IndirectBr: return "indirectbr";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 case Invoke: return "invoke";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 case Resume: return "resume";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 case Unreachable: return "unreachable";
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
300 case CleanupRet: return "cleanupret";
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
301 case CatchRet: return "catchret";
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
302 case CatchPad: return "catchpad";
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
303 case CatchSwitch: return "catchswitch";
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 // Standard binary operators...
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 case Add: return "add";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 case FAdd: return "fadd";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 case Sub: return "sub";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 case FSub: return "fsub";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 case Mul: return "mul";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 case FMul: return "fmul";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 case UDiv: return "udiv";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 case SDiv: return "sdiv";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 case FDiv: return "fdiv";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 case URem: return "urem";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 case SRem: return "srem";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 case FRem: return "frem";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 // Logical operators...
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 case And: return "and";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 case Or : return "or";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 case Xor: return "xor";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 // Memory instructions...
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 case Alloca: return "alloca";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 case Load: return "load";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 case Store: return "store";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 case AtomicCmpXchg: return "cmpxchg";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 case AtomicRMW: return "atomicrmw";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 case Fence: return "fence";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 case GetElementPtr: return "getelementptr";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
332
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 // Convert instructions...
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 case Trunc: return "trunc";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 case ZExt: return "zext";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 case SExt: return "sext";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 case FPTrunc: return "fptrunc";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 case FPExt: return "fpext";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 case FPToUI: return "fptoui";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 case FPToSI: return "fptosi";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 case UIToFP: return "uitofp";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 case SIToFP: return "sitofp";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 case IntToPtr: return "inttoptr";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 case PtrToInt: return "ptrtoint";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 case BitCast: return "bitcast";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 case AddrSpaceCast: return "addrspacecast";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 // Other instructions...
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 case ICmp: return "icmp";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 case FCmp: return "fcmp";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 case PHI: return "phi";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 case Select: return "select";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 case Call: return "call";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 case Shl: return "shl";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 case LShr: return "lshr";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 case AShr: return "ashr";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 case VAArg: return "va_arg";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 case ExtractElement: return "extractelement";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 case InsertElement: return "insertelement";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 case ShuffleVector: return "shufflevector";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 case ExtractValue: return "extractvalue";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 case InsertValue: return "insertvalue";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 case LandingPad: return "landingpad";
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
364 case CleanupPad: return "cleanuppad";
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 default: return "<Invalid operator> ";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
369
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
370 /// Return true if both instructions have the same special state. This must be
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
371 /// kept in sync with FunctionComparator::cmpOperations in
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
372 /// lib/Transforms/IPO/MergeFunctions.cpp.
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
373 static bool haveSameSpecialState(const Instruction *I1, const Instruction *I2,
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
374 bool IgnoreAlignment = false) {
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
375 assert(I1->getOpcode() == I2->getOpcode() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
376 "Can not compare special state of different instructions");
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
377
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
378 if (const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
379 return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
380 (AI->getAlignment() == cast<AllocaInst>(I2)->getAlignment() ||
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
381 IgnoreAlignment);
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
382 if (const LoadInst *LI = dyn_cast<LoadInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
383 return LI->isVolatile() == cast<LoadInst>(I2)->isVolatile() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
384 (LI->getAlignment() == cast<LoadInst>(I2)->getAlignment() ||
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
385 IgnoreAlignment) &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
386 LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
387 LI->getSyncScopeID() == cast<LoadInst>(I2)->getSyncScopeID();
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
388 if (const StoreInst *SI = dyn_cast<StoreInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
389 return SI->isVolatile() == cast<StoreInst>(I2)->isVolatile() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
390 (SI->getAlignment() == cast<StoreInst>(I2)->getAlignment() ||
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
391 IgnoreAlignment) &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
392 SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
393 SI->getSyncScopeID() == cast<StoreInst>(I2)->getSyncScopeID();
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
394 if (const CmpInst *CI = dyn_cast<CmpInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
395 return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
396 if (const CallInst *CI = dyn_cast<CallInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
397 return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
398 CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
399 CI->getAttributes() == cast<CallInst>(I2)->getAttributes() &&
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
400 CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
401 if (const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
402 return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
403 CI->getAttributes() == cast<InvokeInst>(I2)->getAttributes() &&
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
404 CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
405 if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
406 return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
407 if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
408 return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
409 if (const FenceInst *FI = dyn_cast<FenceInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
410 return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
411 FI->getSyncScopeID() == cast<FenceInst>(I2)->getSyncScopeID();
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
412 if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
413 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->isVolatile() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
414 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->isWeak() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
415 CXI->getSuccessOrdering() ==
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
416 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
417 CXI->getFailureOrdering() ==
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
418 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
419 CXI->getSyncScopeID() ==
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
420 cast<AtomicCmpXchgInst>(I2)->getSyncScopeID();
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
421 if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
422 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
423 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->isVolatile() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
424 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
425 RMWI->getSyncScopeID() == cast<AtomicRMWInst>(I2)->getSyncScopeID();
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
426
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
427 return true;
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
428 }
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
429
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 bool Instruction::isIdenticalTo(const Instruction *I) const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 return isIdenticalToWhenDefined(I) &&
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 SubclassOptionalData == I->SubclassOptionalData;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
434
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 bool Instruction::isIdenticalToWhenDefined(const Instruction *I) const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 if (getOpcode() != I->getOpcode() ||
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 getNumOperands() != I->getNumOperands() ||
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 getType() != I->getType())
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
440
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
441 // If both instructions have no operands, they are identical.
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
442 if (getNumOperands() == 0 && I->getNumOperands() == 0)
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
443 return haveSameSpecialState(this, I);
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
444
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 // We have two instructions of identical opcode and #operands. Check to see
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 // if all operands are the same.
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
447 if (!std::equal(op_begin(), op_end(), I->op_begin()))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
448 return false;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
449
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 const PHINode *otherPHI = cast<PHINode>(I);
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
452 return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
453 otherPHI->block_begin());
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 }
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
455
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
456 return haveSameSpecialState(this, I);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
458
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
459 // Keep this in sync with FunctionComparator::cmpOperations in
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 // lib/Transforms/IPO/MergeFunctions.cpp.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 bool Instruction::isSameOperationAs(const Instruction *I,
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 unsigned flags) const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 bool IgnoreAlignment = flags & CompareIgnoringAlignment;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 bool UseScalarTypes = flags & CompareUsingScalarTypes;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
465
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 if (getOpcode() != I->getOpcode() ||
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 getNumOperands() != I->getNumOperands() ||
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 (UseScalarTypes ?
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 getType()->getScalarType() != I->getType()->getScalarType() :
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 getType() != I->getType()))
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
472
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 // We have two instructions of identical opcode and #operands. Check to see
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 // if all operands are the same type
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 if (UseScalarTypes ?
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 getOperand(i)->getType()->getScalarType() !=
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 I->getOperand(i)->getType()->getScalarType() :
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 getOperand(i)->getType() != I->getOperand(i)->getType())
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
481
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
482 return haveSameSpecialState(this, I, IgnoreAlignment);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
484
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 bool Instruction::isUsedOutsideOfBlock(const BasicBlock *BB) const {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
486 for (const Use &U : uses()) {
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 // PHI nodes uses values in the corresponding predecessor block. For other
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 // instructions, just check to see whether the parent of the use matches up.
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
489 const Instruction *I = cast<Instruction>(U.getUser());
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
490 const PHINode *PN = dyn_cast<PHINode>(I);
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
491 if (!PN) {
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
492 if (I->getParent() != BB)
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 return true;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 continue;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
496
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
497 if (PN->getIncomingBlock(U) != BB)
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 return true;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
502
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 bool Instruction::mayReadFromMemory() const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 switch (getOpcode()) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 default: return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 case Instruction::VAArg:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 case Instruction::Load:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 case Instruction::Fence: // FIXME: refine definition of mayReadFromMemory
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 case Instruction::AtomicCmpXchg:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 case Instruction::AtomicRMW:
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
511 case Instruction::CatchPad:
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
512 case Instruction::CatchRet:
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 return true;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 case Instruction::Call:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 return !cast<CallInst>(this)->doesNotAccessMemory();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 case Instruction::Invoke:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 return !cast<InvokeInst>(this)->doesNotAccessMemory();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 case Instruction::Store:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 return !cast<StoreInst>(this)->isUnordered();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
522
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 bool Instruction::mayWriteToMemory() const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 switch (getOpcode()) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 default: return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 case Instruction::Fence: // FIXME: refine definition of mayWriteToMemory
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 case Instruction::Store:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 case Instruction::VAArg:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 case Instruction::AtomicCmpXchg:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 case Instruction::AtomicRMW:
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
531 case Instruction::CatchPad:
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
532 case Instruction::CatchRet:
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 return true;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 case Instruction::Call:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 return !cast<CallInst>(this)->onlyReadsMemory();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 case Instruction::Invoke:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 return !cast<InvokeInst>(this)->onlyReadsMemory();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 case Instruction::Load:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 return !cast<LoadInst>(this)->isUnordered();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
542
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
543 bool Instruction::isAtomic() const {
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
544 switch (getOpcode()) {
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
545 default:
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
546 return false;
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
547 case Instruction::AtomicCmpXchg:
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
548 case Instruction::AtomicRMW:
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
549 case Instruction::Fence:
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
550 return true;
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
551 case Instruction::Load:
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
552 return cast<LoadInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
553 case Instruction::Store:
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
554 return cast<StoreInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
555 }
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
556 }
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
557
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
558 bool Instruction::hasAtomicLoad() const {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
559 assert(isAtomic());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
560 switch (getOpcode()) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
561 default:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
562 return false;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
563 case Instruction::AtomicCmpXchg:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
564 case Instruction::AtomicRMW:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
565 case Instruction::Load:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
566 return true;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
567 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
568 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
569
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
570 bool Instruction::hasAtomicStore() const {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
571 assert(isAtomic());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
572 switch (getOpcode()) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
573 default:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
574 return false;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
575 case Instruction::AtomicCmpXchg:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
576 case Instruction::AtomicRMW:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
577 case Instruction::Store:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
578 return true;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
579 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
580 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
581
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
582 bool Instruction::mayThrow() const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 if (const CallInst *CI = dyn_cast<CallInst>(this))
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 return !CI->doesNotThrow();
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
585 if (const auto *CRI = dyn_cast<CleanupReturnInst>(this))
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
586 return CRI->unwindsToCaller();
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
587 if (const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(this))
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
588 return CatchSwitch->unwindsToCaller();
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 return isa<ResumeInst>(this);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
591
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
592 bool Instruction::isSafeToRemove() const {
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
593 return (!isa<CallInst>(this) || !this->mayHaveSideEffects()) &&
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
594 !isa<TerminatorInst>(this);
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
595 }
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
596
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 bool Instruction::isAssociative() const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 unsigned Opcode = getOpcode();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 if (isAssociative(Opcode))
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 return true;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
601
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 switch (Opcode) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 case FMul:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 case FAdd:
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
605 return cast<FPMathOperator>(this)->isFast();
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 default:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
610
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
611 Instruction *Instruction::cloneImpl() const {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
612 llvm_unreachable("Subclass of Instruction failed to implement cloneImpl");
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
613 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
614
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
615 void Instruction::swapProfMetadata() {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
616 MDNode *ProfileData = getMetadata(LLVMContext::MD_prof);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
617 if (!ProfileData || ProfileData->getNumOperands() != 3 ||
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
618 !isa<MDString>(ProfileData->getOperand(0)))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
619 return;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
620
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
621 MDString *MDName = cast<MDString>(ProfileData->getOperand(0));
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
622 if (MDName->getString() != "branch_weights")
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
623 return;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
624
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
625 // The first operand is the name. Fetch them backwards and build a new one.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
626 Metadata *Ops[] = {ProfileData->getOperand(0), ProfileData->getOperand(2),
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
627 ProfileData->getOperand(1)};
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
628 setMetadata(LLVMContext::MD_prof,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
629 MDNode::get(ProfileData->getContext(), Ops));
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
630 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
631
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
632 void Instruction::copyMetadata(const Instruction &SrcInst,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
633 ArrayRef<unsigned> WL) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
634 if (!SrcInst.hasMetadata())
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
635 return;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
636
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
637 DenseSet<unsigned> WLS;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
638 for (unsigned M : WL)
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
639 WLS.insert(M);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
640
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
641 // Otherwise, enumerate and copy over metadata from the old instruction to the
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
642 // new one.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
643 SmallVector<std::pair<unsigned, MDNode *>, 4> TheMDs;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
644 SrcInst.getAllMetadataOtherThanDebugLoc(TheMDs);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
645 for (const auto &MD : TheMDs) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
646 if (WL.empty() || WLS.count(MD.first))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
647 setMetadata(MD.first, MD.second);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
648 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
649 if (WL.empty() || WLS.count(LLVMContext::MD_dbg))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
650 setDebugLoc(SrcInst.getDebugLoc());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
651 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
652
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 Instruction *Instruction::clone() const {
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
654 Instruction *New = nullptr;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
655 switch (getOpcode()) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
656 default:
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
657 llvm_unreachable("Unhandled Opcode.");
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
658 #define HANDLE_INST(num, opc, clas) \
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
659 case Instruction::opc: \
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
660 New = cast<clas>(this)->cloneImpl(); \
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
661 break;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
662 #include "llvm/IR/Instruction.def"
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
663 #undef HANDLE_INST
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
664 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
665
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 New->SubclassOptionalData = SubclassOptionalData;
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
667 New->copyMetadata(*this);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
668 return New;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
669 }
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
670
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
671 void Instruction::updateProfWeight(uint64_t S, uint64_t T) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
672 auto *ProfileData = getMetadata(LLVMContext::MD_prof);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
673 if (ProfileData == nullptr)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
674 return;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
675
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
676 auto *ProfDataName = dyn_cast<MDString>(ProfileData->getOperand(0));
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
677 if (!ProfDataName || (!ProfDataName->getString().equals("branch_weights") &&
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
678 !ProfDataName->getString().equals("VP")))
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
679 return;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
680
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
681 MDBuilder MDB(getContext());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
682 SmallVector<Metadata *, 3> Vals;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
683 Vals.push_back(ProfileData->getOperand(0));
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
684 APInt APS(128, S), APT(128, T);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
685 if (ProfDataName->getString().equals("branch_weights"))
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
686 for (unsigned i = 1; i < ProfileData->getNumOperands(); i++) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
687 // Using APInt::div may be expensive, but most cases should fit 64 bits.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
688 APInt Val(128,
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
689 mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(i))
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
690 ->getValue()
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
691 .getZExtValue());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
692 Val *= APS;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
693 Vals.push_back(MDB.createConstant(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
694 ConstantInt::get(Type::getInt64Ty(getContext()),
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
695 Val.udiv(APT).getLimitedValue())));
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
696 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
697 else if (ProfDataName->getString().equals("VP"))
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
698 for (unsigned i = 1; i < ProfileData->getNumOperands(); i += 2) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
699 // The first value is the key of the value profile, which will not change.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
700 Vals.push_back(ProfileData->getOperand(i));
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
701 // Using APInt::div may be expensive, but most cases should fit 64 bits.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
702 APInt Val(128,
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
703 mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(i + 1))
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
704 ->getValue()
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
705 .getZExtValue());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
706 Val *= APS;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
707 Vals.push_back(MDB.createConstant(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
708 ConstantInt::get(Type::getInt64Ty(getContext()),
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
709 Val.udiv(APT).getLimitedValue())));
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
710 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
711 setMetadata(LLVMContext::MD_prof, MDNode::get(getContext(), Vals));
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
712 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
713
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
714 void Instruction::setProfWeight(uint64_t W) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
715 assert((isa<CallInst>(this) || isa<InvokeInst>(this)) &&
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
716 "Can only set weights for call and invoke instrucitons");
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
717 SmallVector<uint32_t, 1> Weights;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
718 Weights.push_back(W);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
719 MDBuilder MDB(getContext());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
720 setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(Weights));
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
721 }