@@ -122,84 +122,69 @@ template <> struct DenseMapInfo<GVN::Expression> {
122
122
// / location of the instruction from which it was formed.
123
123
struct llvm ::gvn::AvailableValue {
124
124
enum ValType {
125
- SimpleVal, // A simple offsetted value that is accessed.
126
- LoadVal, // A value produced by a load.
127
- MemIntrinVal, // A memory intrinsic which is loaded from.
128
- UndefVal, // A UndefValue representing a value from dead block (which
129
- // is not yet physically removed from the CFG).
130
- CreateLoadVal // A duplicate load can be created higher up in the CFG that
131
- // will eliminate this one.
125
+ SimpleVal, // A simple offsetted value that is accessed.
126
+ LoadVal, // A value produced by a load.
127
+ MemIntrin, // A memory intrinsic which is loaded from.
128
+ UndefVal // A UndefValue representing a value from dead block (which
129
+ // is not yet physically removed from the CFG).
132
130
};
133
131
134
132
// / V - The value that is live out of the block.
135
- std::pair <Value *, ValType> Val;
133
+ PointerIntPair <Value *, 2 , ValType> Val;
136
134
137
135
// / Offset - The byte offset in Val that is interesting for the load query.
138
136
unsigned Offset;
139
137
140
138
static AvailableValue get (Value *V, unsigned Offset = 0 ) {
141
139
AvailableValue Res;
142
- Res.Val .first = V ;
143
- Res.Val .second = SimpleVal;
140
+ Res.Val .setPointer (V) ;
141
+ Res.Val .setInt ( SimpleVal) ;
144
142
Res.Offset = Offset;
145
143
return Res;
146
144
}
147
145
148
146
static AvailableValue getMI (MemIntrinsic *MI, unsigned Offset = 0 ) {
149
147
AvailableValue Res;
150
- Res.Val .first = MI ;
151
- Res.Val .second = MemIntrinVal ;
148
+ Res.Val .setPointer (MI) ;
149
+ Res.Val .setInt (MemIntrin) ;
152
150
Res.Offset = Offset;
153
151
return Res;
154
152
}
155
153
156
- static AvailableValue getCreateLoad (LoadInst *LI) {
157
- AvailableValue Res;
158
- Res.Val .first = LI;
159
- Res.Val .second = CreateLoadVal;
160
- return Res;
161
- }
162
-
163
154
static AvailableValue getLoad (LoadInst *LI, unsigned Offset = 0 ) {
164
155
AvailableValue Res;
165
- Res.Val .first = LI ;
166
- Res.Val .second = LoadVal;
156
+ Res.Val .setPointer (LI) ;
157
+ Res.Val .setInt ( LoadVal) ;
167
158
Res.Offset = Offset;
168
159
return Res;
169
160
}
170
161
171
162
static AvailableValue getUndef () {
172
163
AvailableValue Res;
173
- Res.Val .first = nullptr ;
174
- Res.Val .second = UndefVal;
164
+ Res.Val .setPointer ( nullptr ) ;
165
+ Res.Val .setInt ( UndefVal) ;
175
166
Res.Offset = 0 ;
176
167
return Res;
177
168
}
178
169
179
- bool isSimpleValue () const { return Val.second == SimpleVal; }
180
- bool isCoercedLoadValue () const { return Val.second == LoadVal; }
181
- bool isMemIntrinValue () const { return Val.second == MemIntrinVal; }
182
- bool isUndefValue () const { return Val.second == UndefVal; }
183
- bool isCreateLoadValue () const { return Val.second == CreateLoadVal; }
184
-
185
- LoadInst *getCreateLoadValue () const {
186
- assert (isCreateLoadValue () && " Wrong accessor" );
187
- return cast<LoadInst>(Val.first );
188
- }
170
+ bool isSimpleValue () const { return Val.getInt () == SimpleVal; }
171
+ bool isCoercedLoadValue () const { return Val.getInt () == LoadVal; }
172
+ bool isMemIntrinValue () const { return Val.getInt () == MemIntrin; }
173
+ bool isUndefValue () const { return Val.getInt () == UndefVal; }
189
174
190
175
Value *getSimpleValue () const {
191
176
assert (isSimpleValue () && " Wrong accessor" );
192
- return Val.first ;
177
+ return Val.getPointer () ;
193
178
}
194
179
195
180
LoadInst *getCoercedLoadValue () const {
196
181
assert (isCoercedLoadValue () && " Wrong accessor" );
197
- return cast<LoadInst>(Val.first );
182
+ return cast<LoadInst>(Val.getPointer () );
198
183
}
199
184
200
185
MemIntrinsic *getMemIntrinValue () const {
201
186
assert (isMemIntrinValue () && " Wrong accessor" );
202
- return cast<MemIntrinsic>(Val.first );
187
+ return cast<MemIntrinsic>(Val.getPointer () );
203
188
}
204
189
205
190
// / Emit code at the specified insertion point to adjust the value defined
@@ -1180,11 +1165,7 @@ Value *AvailableValue::MaterializeAdjustedValue(LoadInst *LI,
1180
1165
Value *Res;
1181
1166
Type *LoadTy = LI->getType ();
1182
1167
const DataLayout &DL = LI->getModule ()->getDataLayout ();
1183
- if (isCreateLoadValue ()) {
1184
- Instruction *I = getCreateLoadValue ()->clone ();
1185
- I->insertBefore (InsertPt);
1186
- Res = I;
1187
- } else if (isSimpleValue ()) {
1168
+ if (isSimpleValue ()) {
1188
1169
Res = getSimpleValue ();
1189
1170
if (Res->getType () != LoadTy) {
1190
1171
Res = GetStoreValueForLoad (Res, Offset, LoadTy, InsertPt, DL);
@@ -1372,7 +1353,7 @@ void GVN::AnalyzeLoadAvailability(LoadInst *LI, LoadDepVect &Deps,
1372
1353
continue ;
1373
1354
}
1374
1355
1375
- if (!DepInfo.isDef () && !DepInfo.isClobber () && !DepInfo. isNonFuncLocal () ) {
1356
+ if (!DepInfo.isDef () && !DepInfo.isClobber ()) {
1376
1357
UnavailableBlocks.push_back (DepBB);
1377
1358
continue ;
1378
1359
}
@@ -1383,25 +1364,12 @@ void GVN::AnalyzeLoadAvailability(LoadInst *LI, LoadDepVect &Deps,
1383
1364
Value *Address = Deps[i].getAddress ();
1384
1365
1385
1366
AvailableValue AV;
1386
- // TODO: We can use anything where the operands are available, and we should
1387
- // learn to recreate operands in other blocks if they are available.
1388
- // Because we don't have the infrastructure in our PRE, we restrict this to
1389
- // global values, because we know the operands are always available.
1390
- if (DepInfo.isNonFuncLocal ()) {
1391
- if (isSafeToSpeculativelyExecute (LI) &&
1392
- isa<GlobalValue>(LI->getPointerOperand ())) {
1393
- AV = AvailableValue::getCreateLoad (LI);
1394
- ValuesPerBlock.push_back (AvailableValueInBlock::get (
1395
- &LI->getParent ()->getParent ()->getEntryBlock (), std::move (AV)));
1396
- } else
1397
- UnavailableBlocks.push_back (DepBB);
1398
-
1399
- } else if (AnalyzeLoadAvailability (LI, DepInfo, Address, AV)) {
1367
+ if (AnalyzeLoadAvailability (LI, DepInfo, Address, AV)) {
1400
1368
// subtlety: because we know this was a non-local dependency, we know
1401
1369
// it's safe to materialize anywhere between the instruction within
1402
1370
// DepInfo and the end of it's block.
1403
- ValuesPerBlock.push_back (
1404
- AvailableValueInBlock::get (DepBB, std::move (AV)));
1371
+ ValuesPerBlock.push_back (AvailableValueInBlock::get (DepBB,
1372
+ std::move (AV)));
1405
1373
} else {
1406
1374
UnavailableBlocks.push_back (DepBB);
1407
1375
}
0 commit comments