MCPcopy Create free account
hub / github.com/AliveToolkit/alive2 / genInst

Method genInst

tools/quick-fuzz.cpp:206–264  ·  view source on GitHub ↗

TODO generate vector instructions

Source from the content-addressed store, hash-verified

204
205 // TODO generate vector instructions
206 Value *genInst() {
207 auto *Ty = Type::getIntNTy(BB->getContext(), getWidth(WP));
208 Value *Val = nullptr;
209 switch (C.choose(4)) {
210 case 0: {
211 auto *LHS = getVal(Ty);
212 auto *RHS = getVal(Ty);
213 Val = new ICmpInst(BB, randomPred(), LHS, RHS);
214 } break;
215 case 1: {
216 auto *LHS = getVal(Ty);
217 Value *RHS = getVal(Ty);
218 auto NarrowWidth = ilog2_ceil(Ty->getIntegerBitWidth() - 1, true);
219 auto *NarrowTy = Type::getIntNTy(BB->getContext(), NarrowWidth);
220 auto *Mask = ConstantInt::get(Ty, (1UL << NarrowWidth) - 1);
221 auto *AltRHS = C.flip() ? adapt(adapt(RHS, NarrowTy, "mask"), Ty, "mask")
222 : BinaryOperator::Create(BinaryOperator::And, RHS,
223 Mask, "mask", BB);
224 BinaryOperator *BinOp = randomBinop(LHS, PoisonValue::get(Ty));
225 Val = BinOp;
226 auto Op = BinOp->getOpcode();
227 bool isConst = isa<ConstantInt>(RHS);
228 // all literal constants and some variable inputs should be
229 // truncated to avoid too much poison due to OOB shift exponents
230 if ((Op == BinaryOperator::LShr || Op == BinaryOperator::AShr ||
231 Op == BinaryOperator::Shl) &&
232 (isConst || C.flip())) {
233 BinOp->setOperand(1, AltRHS);
234 } else {
235 BinOp->setOperand(1, RHS);
236 }
237 } break;
238 case 2: {
239 auto *LHS = getVal(Ty);
240 auto *RHS = getVal(Ty);
241 auto *Cond = getVal(Type::getInt1Ty(BB->getContext()));
242 Val = SelectInst::Create(Cond, LHS, RHS, "", BB);
243 } break;
244 case 3: {
245 switch (C.choose(3)) {
246 case 0:
247 Val = genUnaryIntrinsic(Ty);
248 break;
249 case 1:
250 Val = genBinaryIntrinsic(Ty);
251 break;
252 case 2:
253 Val = genTernaryIntrinsic(Ty);
254 break;
255 default:
256 assert(false);
257 }
258 } break;
259 default:
260 assert(false);
261 }
262 Vals.push_back(Val);
263 return Val;

Callers 1

goMethod · 0.80

Calls 3

ilog2_ceilFunction · 0.85
chooseMethod · 0.80
flipMethod · 0.80

Tested by

no test coverage detected