annotate lib/IR/Instruction.cpp @ 148:63bd29f05246

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 19:46:37 +0900
parents c2174574ed3a
children
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 //
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 //
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 // 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
10 //
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
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
13 #include "llvm/IR/Instruction.h"
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
14 #include "llvm/IR/IntrinsicInst.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 }
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
141 // TODO: FastMathFlags!
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
142 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
143
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
144
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
145 bool Instruction::isExact() const {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
146 return cast<PossiblyExactOperator>(this)->isExact();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
147 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
148
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
149 void Instruction::setFast(bool B) {
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
151 cast<FPMathOperator>(this)->setFast(B);
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
152 }
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
153
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
154 void Instruction::setHasAllowReassoc(bool B) {
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
155 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
156 cast<FPMathOperator>(this)->setHasAllowReassoc(B);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 void Instruction::setHasNoNaNs(bool B) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 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
161 cast<FPMathOperator>(this)->setHasNoNaNs(B);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 void Instruction::setHasNoInfs(bool B) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 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
166 cast<FPMathOperator>(this)->setHasNoInfs(B);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 void Instruction::setHasNoSignedZeros(bool B) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 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
171 cast<FPMathOperator>(this)->setHasNoSignedZeros(B);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 void Instruction::setHasAllowReciprocal(bool B) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 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
176 cast<FPMathOperator>(this)->setHasAllowReciprocal(B);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
179 void Instruction::setHasApproxFunc(bool B) {
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
180 assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
181 cast<FPMathOperator>(this)->setHasApproxFunc(B);
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
182 }
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
183
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 void Instruction::setFastMathFlags(FastMathFlags FMF) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 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
186 cast<FPMathOperator>(this)->setFastMathFlags(FMF);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
189 void Instruction::copyFastMathFlags(FastMathFlags FMF) {
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
190 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
191 cast<FPMathOperator>(this)->copyFastMathFlags(FMF);
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
192 }
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
193
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
194 bool Instruction::isFast() const {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
195 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
196 return cast<FPMathOperator>(this)->isFast();
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
197 }
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
198
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
199 bool Instruction::hasAllowReassoc() const {
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
200 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
201 return cast<FPMathOperator>(this)->hasAllowReassoc();
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 bool Instruction::hasNoNaNs() const {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
205 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
206 return cast<FPMathOperator>(this)->hasNoNaNs();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 bool Instruction::hasNoInfs() const {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
210 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
211 return cast<FPMathOperator>(this)->hasNoInfs();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 bool Instruction::hasNoSignedZeros() const {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
215 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
216 return cast<FPMathOperator>(this)->hasNoSignedZeros();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 bool Instruction::hasAllowReciprocal() const {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
220 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
221 return cast<FPMathOperator>(this)->hasAllowReciprocal();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
224 bool Instruction::hasAllowContract() const {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
225 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
226 return cast<FPMathOperator>(this)->hasAllowContract();
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
227 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
228
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
229 bool Instruction::hasApproxFunc() const {
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
230 assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
231 return cast<FPMathOperator>(this)->hasApproxFunc();
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
232 }
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
233
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 FastMathFlags Instruction::getFastMathFlags() const {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
235 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
236 return cast<FPMathOperator>(this)->getFastMathFlags();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 void Instruction::copyFastMathFlags(const Instruction *I) {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
240 copyFastMathFlags(I->getFastMathFlags());
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
243 void Instruction::copyIRFlags(const Value *V, bool IncludeWrapFlags) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
244 // Copy the wrapping flags.
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
245 if (IncludeWrapFlags && isa<OverflowingBinaryOperator>(this)) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
246 if (auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
247 setHasNoSignedWrap(OB->hasNoSignedWrap());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
248 setHasNoUnsignedWrap(OB->hasNoUnsignedWrap());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
249 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
250 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
251
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
252 // Copy the exact flag.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
253 if (auto *PE = dyn_cast<PossiblyExactOperator>(V))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
254 if (isa<PossiblyExactOperator>(this))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
255 setIsExact(PE->isExact());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
256
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
257 // Copy the fast-math flags.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
258 if (auto *FP = dyn_cast<FPMathOperator>(V))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
259 if (isa<FPMathOperator>(this))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
260 copyFastMathFlags(FP->getFastMathFlags());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
261
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
262 if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
263 if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
264 DestGEP->setIsInBounds(SrcGEP->isInBounds() | DestGEP->isInBounds());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
265 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
266
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
267 void Instruction::andIRFlags(const Value *V) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
268 if (auto *OB = dyn_cast<OverflowingBinaryOperator>(V)) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
269 if (isa<OverflowingBinaryOperator>(this)) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
270 setHasNoSignedWrap(hasNoSignedWrap() & OB->hasNoSignedWrap());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
271 setHasNoUnsignedWrap(hasNoUnsignedWrap() & OB->hasNoUnsignedWrap());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
272 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
273 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
274
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
275 if (auto *PE = dyn_cast<PossiblyExactOperator>(V))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
276 if (isa<PossiblyExactOperator>(this))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
277 setIsExact(isExact() & PE->isExact());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
278
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
279 if (auto *FP = dyn_cast<FPMathOperator>(V)) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
280 if (isa<FPMathOperator>(this)) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
281 FastMathFlags FM = getFastMathFlags();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
282 FM &= FP->getFastMathFlags();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
283 copyFastMathFlags(FM);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
284 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
285 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
286
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
287 if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
288 if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
289 DestGEP->setIsInBounds(SrcGEP->isInBounds() & DestGEP->isInBounds());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
290 }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
291
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 const char *Instruction::getOpcodeName(unsigned OpCode) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 switch (OpCode) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 // Terminators
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 case Ret: return "ret";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 case Br: return "br";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 case Switch: return "switch";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 case IndirectBr: return "indirectbr";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 case Invoke: return "invoke";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 case Resume: return "resume";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 case Unreachable: return "unreachable";
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
302 case CleanupRet: return "cleanupret";
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
303 case CatchRet: return "catchret";
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
304 case CatchPad: return "catchpad";
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
305 case CatchSwitch: return "catchswitch";
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
306 case CallBr: return "callbr";
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
307
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
308 // Standard unary operators...
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
309 case FNeg: return "fneg";
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 // Standard binary operators...
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 case Add: return "add";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 case FAdd: return "fadd";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 case Sub: return "sub";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 case FSub: return "fsub";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 case Mul: return "mul";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 case FMul: return "fmul";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 case UDiv: return "udiv";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 case SDiv: return "sdiv";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 case FDiv: return "fdiv";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 case URem: return "urem";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 case SRem: return "srem";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 case FRem: return "frem";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 // Logical operators...
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 case And: return "and";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 case Or : return "or";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 case Xor: return "xor";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 // Memory instructions...
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 case Alloca: return "alloca";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 case Load: return "load";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 case Store: return "store";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 case AtomicCmpXchg: return "cmpxchg";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 case AtomicRMW: return "atomicrmw";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 case Fence: return "fence";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 case GetElementPtr: return "getelementptr";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 // Convert instructions...
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 case Trunc: return "trunc";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 case ZExt: return "zext";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 case SExt: return "sext";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 case FPTrunc: return "fptrunc";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 case FPExt: return "fpext";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 case FPToUI: return "fptoui";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 case FPToSI: return "fptosi";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 case UIToFP: return "uitofp";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 case SIToFP: return "sitofp";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 case IntToPtr: return "inttoptr";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 case PtrToInt: return "ptrtoint";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 case BitCast: return "bitcast";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 case AddrSpaceCast: return "addrspacecast";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 // Other instructions...
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 case ICmp: return "icmp";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 case FCmp: return "fcmp";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 case PHI: return "phi";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 case Select: return "select";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 case Call: return "call";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 case Shl: return "shl";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 case LShr: return "lshr";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 case AShr: return "ashr";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 case VAArg: return "va_arg";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 case ExtractElement: return "extractelement";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 case InsertElement: return "insertelement";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 case ShuffleVector: return "shufflevector";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 case ExtractValue: return "extractvalue";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 case InsertValue: return "insertvalue";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 case LandingPad: return "landingpad";
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
370 case CleanupPad: return "cleanuppad";
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
371
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 default: return "<Invalid operator> ";
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
375
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
376 /// Return true if both instructions have the same special state. This must be
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
377 /// kept in sync with FunctionComparator::cmpOperations in
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
378 /// lib/Transforms/IPO/MergeFunctions.cpp.
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
379 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
380 bool IgnoreAlignment = false) {
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
381 assert(I1->getOpcode() == I2->getOpcode() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
382 "Can not compare special state of different instructions");
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
383
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
384 if (const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
385 return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
386 (AI->getAlignment() == cast<AllocaInst>(I2)->getAlignment() ||
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
387 IgnoreAlignment);
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
388 if (const LoadInst *LI = dyn_cast<LoadInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
389 return LI->isVolatile() == cast<LoadInst>(I2)->isVolatile() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
390 (LI->getAlignment() == cast<LoadInst>(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 LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
393 LI->getSyncScopeID() == cast<LoadInst>(I2)->getSyncScopeID();
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
394 if (const StoreInst *SI = dyn_cast<StoreInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
395 return SI->isVolatile() == cast<StoreInst>(I2)->isVolatile() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
396 (SI->getAlignment() == cast<StoreInst>(I2)->getAlignment() ||
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
397 IgnoreAlignment) &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
398 SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
399 SI->getSyncScopeID() == cast<StoreInst>(I2)->getSyncScopeID();
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
400 if (const CmpInst *CI = dyn_cast<CmpInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
401 return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
402 if (const CallInst *CI = dyn_cast<CallInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
403 return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
404 CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
405 CI->getAttributes() == cast<CallInst>(I2)->getAttributes() &&
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
406 CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
407 if (const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
408 return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
409 CI->getAttributes() == cast<InvokeInst>(I2)->getAttributes() &&
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
410 CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
411 if (const CallBrInst *CI = dyn_cast<CallBrInst>(I1))
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
412 return CI->getCallingConv() == cast<CallBrInst>(I2)->getCallingConv() &&
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
413 CI->getAttributes() == cast<CallBrInst>(I2)->getAttributes() &&
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
414 CI->hasIdenticalOperandBundleSchema(*cast<CallBrInst>(I2));
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
415 if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
416 return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
417 if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
418 return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
419 if (const FenceInst *FI = dyn_cast<FenceInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
420 return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
421 FI->getSyncScopeID() == cast<FenceInst>(I2)->getSyncScopeID();
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
422 if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
423 return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->isVolatile() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
424 CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->isWeak() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
425 CXI->getSuccessOrdering() ==
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
426 cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
427 CXI->getFailureOrdering() ==
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
428 cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
429 CXI->getSyncScopeID() ==
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
430 cast<AtomicCmpXchgInst>(I2)->getSyncScopeID();
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
431 if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(I1))
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
432 return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
433 RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->isVolatile() &&
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
434 RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
435 RMWI->getSyncScopeID() == cast<AtomicRMWInst>(I2)->getSyncScopeID();
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
436
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
437 return true;
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
438 }
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
439
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 bool Instruction::isIdenticalTo(const Instruction *I) const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 return isIdenticalToWhenDefined(I) &&
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 SubclassOptionalData == I->SubclassOptionalData;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
444
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 bool Instruction::isIdenticalToWhenDefined(const Instruction *I) const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 if (getOpcode() != I->getOpcode() ||
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 getNumOperands() != I->getNumOperands() ||
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 getType() != I->getType())
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
450
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
451 // 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
452 if (getNumOperands() == 0 && I->getNumOperands() == 0)
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
453 return haveSameSpecialState(this, I);
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
454
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 // 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
456 // if all operands are the same.
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
457 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
458 return false;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
459
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 const PHINode *otherPHI = cast<PHINode>(I);
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
462 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
463 otherPHI->block_begin());
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 }
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
465
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
466 return haveSameSpecialState(this, I);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
468
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
469 // Keep this in sync with FunctionComparator::cmpOperations in
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 // lib/Transforms/IPO/MergeFunctions.cpp.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 bool Instruction::isSameOperationAs(const Instruction *I,
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 unsigned flags) const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 bool IgnoreAlignment = flags & CompareIgnoringAlignment;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 bool UseScalarTypes = flags & CompareUsingScalarTypes;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
475
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 if (getOpcode() != I->getOpcode() ||
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 getNumOperands() != I->getNumOperands() ||
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 (UseScalarTypes ?
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 getType()->getScalarType() != I->getType()->getScalarType() :
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 getType() != I->getType()))
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
482
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 // 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
484 // if all operands are the same type
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 if (UseScalarTypes ?
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 getOperand(i)->getType()->getScalarType() !=
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 I->getOperand(i)->getType()->getScalarType() :
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 getOperand(i)->getType() != I->getOperand(i)->getType())
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
491
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
492 return haveSameSpecialState(this, I, IgnoreAlignment);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
494
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 bool Instruction::isUsedOutsideOfBlock(const BasicBlock *BB) const {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
496 for (const Use &U : uses()) {
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 // 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
498 // 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
499 const Instruction *I = cast<Instruction>(U.getUser());
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
500 const PHINode *PN = dyn_cast<PHINode>(I);
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
501 if (!PN) {
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
502 if (I->getParent() != BB)
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 return true;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 continue;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
506
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
507 if (PN->getIncomingBlock(U) != BB)
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 return true;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
512
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 bool Instruction::mayReadFromMemory() const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 switch (getOpcode()) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 default: return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 case Instruction::VAArg:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 case Instruction::Load:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 case Instruction::Fence: // FIXME: refine definition of mayReadFromMemory
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 case Instruction::AtomicCmpXchg:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 case Instruction::AtomicRMW:
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
521 case Instruction::CatchPad:
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
522 case Instruction::CatchRet:
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 return true;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 case Instruction::Call:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 case Instruction::Invoke:
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
526 case Instruction::CallBr:
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
527 return !cast<CallBase>(this)->doesNotAccessMemory();
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 case Instruction::Store:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 return !cast<StoreInst>(this)->isUnordered();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
532
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 bool Instruction::mayWriteToMemory() const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 switch (getOpcode()) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 default: return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 case Instruction::Fence: // FIXME: refine definition of mayWriteToMemory
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 case Instruction::Store:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 case Instruction::VAArg:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 case Instruction::AtomicCmpXchg:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 case Instruction::AtomicRMW:
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
541 case Instruction::CatchPad:
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
542 case Instruction::CatchRet:
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 return true;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 case Instruction::Call:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 case Instruction::Invoke:
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
546 case Instruction::CallBr:
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
547 return !cast<CallBase>(this)->onlyReadsMemory();
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 case Instruction::Load:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 return !cast<LoadInst>(this)->isUnordered();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
552
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
553 bool Instruction::isAtomic() const {
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
554 switch (getOpcode()) {
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
555 default:
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
556 return false;
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
557 case Instruction::AtomicCmpXchg:
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
558 case Instruction::AtomicRMW:
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
559 case Instruction::Fence:
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
560 return true;
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
561 case Instruction::Load:
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
562 return cast<LoadInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
563 case Instruction::Store:
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
564 return cast<StoreInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
565 }
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
566 }
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
567
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
568 bool Instruction::hasAtomicLoad() const {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
569 assert(isAtomic());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
570 switch (getOpcode()) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
571 default:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
572 return false;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
573 case Instruction::AtomicCmpXchg:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
574 case Instruction::AtomicRMW:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
575 case Instruction::Load:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
576 return true;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
577 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
578 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
579
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
580 bool Instruction::hasAtomicStore() const {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
581 assert(isAtomic());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
582 switch (getOpcode()) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
583 default:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
584 return false;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
585 case Instruction::AtomicCmpXchg:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
586 case Instruction::AtomicRMW:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
587 case Instruction::Store:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
588 return true;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
589 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
590 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
591
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 bool Instruction::mayThrow() const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 if (const CallInst *CI = dyn_cast<CallInst>(this))
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 return !CI->doesNotThrow();
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
595 if (const auto *CRI = dyn_cast<CleanupReturnInst>(this))
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
596 return CRI->unwindsToCaller();
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
597 if (const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(this))
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
598 return CatchSwitch->unwindsToCaller();
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 return isa<ResumeInst>(this);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
601
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
602 bool Instruction::isSafeToRemove() const {
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
603 return (!isa<CallInst>(this) || !this->mayHaveSideEffects()) &&
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
604 !this->isTerminator();
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
605 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
606
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
607 bool Instruction::isLifetimeStartOrEnd() const {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
608 auto II = dyn_cast<IntrinsicInst>(this);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
609 if (!II)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
610 return false;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
611 Intrinsic::ID ID = II->getIntrinsicID();
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
612 return ID == Intrinsic::lifetime_start || ID == Intrinsic::lifetime_end;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
613 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
614
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
615 const Instruction *Instruction::getNextNonDebugInstruction() const {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
616 for (const Instruction *I = getNextNode(); I; I = I->getNextNode())
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
617 if (!isa<DbgInfoIntrinsic>(I))
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
618 return I;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
619 return nullptr;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
620 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
621
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
622 const Instruction *Instruction::getPrevNonDebugInstruction() const {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
623 for (const Instruction *I = getPrevNode(); I; I = I->getPrevNode())
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
624 if (!isa<DbgInfoIntrinsic>(I))
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
625 return I;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
626 return nullptr;
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
627 }
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
628
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 bool Instruction::isAssociative() const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 unsigned Opcode = getOpcode();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
631 if (isAssociative(Opcode))
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
632 return true;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
633
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
634 switch (Opcode) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
635 case FMul:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 case FAdd:
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
637 return cast<FPMathOperator>(this)->hasAllowReassoc() &&
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
638 cast<FPMathOperator>(this)->hasNoSignedZeros();
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
639 default:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
640 return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
642 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
643
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
644 unsigned Instruction::getNumSuccessors() const {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
645 switch (getOpcode()) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
646 #define HANDLE_TERM_INST(N, OPC, CLASS) \
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
647 case Instruction::OPC: \
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
648 return static_cast<const CLASS *>(this)->getNumSuccessors();
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
649 #include "llvm/IR/Instruction.def"
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
650 default:
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
651 break;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
652 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
653 llvm_unreachable("not a terminator");
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
654 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
655
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
656 BasicBlock *Instruction::getSuccessor(unsigned idx) const {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
657 switch (getOpcode()) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
658 #define HANDLE_TERM_INST(N, OPC, CLASS) \
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
659 case Instruction::OPC: \
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
660 return static_cast<const CLASS *>(this)->getSuccessor(idx);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
661 #include "llvm/IR/Instruction.def"
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
662 default:
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
663 break;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
664 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
665 llvm_unreachable("not a terminator");
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
666 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
667
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
668 void Instruction::setSuccessor(unsigned idx, BasicBlock *B) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
669 switch (getOpcode()) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
670 #define HANDLE_TERM_INST(N, OPC, CLASS) \
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
671 case Instruction::OPC: \
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
672 return static_cast<CLASS *>(this)->setSuccessor(idx, B);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
673 #include "llvm/IR/Instruction.def"
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
674 default:
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
675 break;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
676 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
677 llvm_unreachable("not a terminator");
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
678 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
679
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
680 void Instruction::replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
681 for (unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
682 Idx != NumSuccessors; ++Idx)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
683 if (getSuccessor(Idx) == OldBB)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
684 setSuccessor(Idx, NewBB);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
685 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
686
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
687 Instruction *Instruction::cloneImpl() const {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
688 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
689 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
690
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
691 void Instruction::swapProfMetadata() {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
692 MDNode *ProfileData = getMetadata(LLVMContext::MD_prof);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
693 if (!ProfileData || ProfileData->getNumOperands() != 3 ||
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
694 !isa<MDString>(ProfileData->getOperand(0)))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
695 return;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
696
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
697 MDString *MDName = cast<MDString>(ProfileData->getOperand(0));
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
698 if (MDName->getString() != "branch_weights")
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
699 return;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
700
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
701 // The first operand is the name. Fetch them backwards and build a new one.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
702 Metadata *Ops[] = {ProfileData->getOperand(0), ProfileData->getOperand(2),
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
703 ProfileData->getOperand(1)};
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
704 setMetadata(LLVMContext::MD_prof,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
705 MDNode::get(ProfileData->getContext(), Ops));
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
706 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
707
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
708 void Instruction::copyMetadata(const Instruction &SrcInst,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
709 ArrayRef<unsigned> WL) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
710 if (!SrcInst.hasMetadata())
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
711 return;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
712
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
713 DenseSet<unsigned> WLS;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
714 for (unsigned M : WL)
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
715 WLS.insert(M);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
716
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
717 // Otherwise, enumerate and copy over metadata from the old instruction to the
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
718 // new one.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
719 SmallVector<std::pair<unsigned, MDNode *>, 4> TheMDs;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
720 SrcInst.getAllMetadataOtherThanDebugLoc(TheMDs);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
721 for (const auto &MD : TheMDs) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
722 if (WL.empty() || WLS.count(MD.first))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
723 setMetadata(MD.first, MD.second);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
724 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
725 if (WL.empty() || WLS.count(LLVMContext::MD_dbg))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
726 setDebugLoc(SrcInst.getDebugLoc());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
727 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
728
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 Instruction *Instruction::clone() const {
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
730 Instruction *New = nullptr;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
731 switch (getOpcode()) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
732 default:
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
733 llvm_unreachable("Unhandled Opcode.");
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
734 #define HANDLE_INST(num, opc, clas) \
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
735 case Instruction::opc: \
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
736 New = cast<clas>(this)->cloneImpl(); \
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
737 break;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
738 #include "llvm/IR/Instruction.def"
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
739 #undef HANDLE_INST
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
740 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
741
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
742 New->SubclassOptionalData = SubclassOptionalData;
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
743 New->copyMetadata(*this);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
744 return New;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
745 }
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
746
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
747 void Instruction::setProfWeight(uint64_t W) {
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
748 assert(isa<CallBase>(this) &&
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
749 "Can only set weights for call like instructions");
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
750 SmallVector<uint32_t, 1> Weights;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
751 Weights.push_back(W);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
752 MDBuilder MDB(getContext());
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
753 setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(Weights));
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
754 }