return EraseInstFromFunction(CI);
break;
}
+ case Intrinsic::objectsize: {
+ ConstantInt *Const = dyn_cast<ConstantInt>(II->getOperand(2));
+
+ if (!Const) return 0;
+
+ const Type *Ty = CI.getType();
+
+ if (Const->getZExtValue() == 0)
+ return ReplaceInstUsesWith(CI, Constant::getAllOnesValue(Ty));
+ else
+ return ReplaceInstUsesWith(CI, ConstantInt::get(Ty, 0));
+ }
}
return visitCallSite(II);
// Object Size Checking Optimizations
//===----------------------------------------------------------------------===//
-//===---------------------------------------===//
-// 'object size'
-namespace {
-struct SizeOpt : public LibCallOptimization {
- virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
- // TODO: We can do more with this, but delaying to here should be no change
- // in behavior.
- ConstantInt *Const = dyn_cast<ConstantInt>(CI->getOperand(2));
-
- if (!Const) return 0;
-
- const Type *Ty = Callee->getFunctionType()->getReturnType();
-
- if (Const->getZExtValue() == 0)
- return Constant::getAllOnesValue(Ty);
- else
- return ConstantInt::get(Ty, 0);
- }
-};
-}
-
//===---------------------------------------===//
// 'memcpy_chk' Optimizations
FWriteOpt FWrite; FPutsOpt FPuts; FPrintFOpt FPrintF;
// Object Size Checking
- SizeOpt ObjectSize;
MemCpyChkOpt MemCpyChk; MemSetChkOpt MemSetChk; MemMoveChkOpt MemMoveChk;
bool Modified; // This is only used by doInitialization.
Optimizations["fprintf"] = &FPrintF;
// Object Size Checking
- Optimizations["llvm.objectsize.i32"] = &ObjectSize;
- Optimizations["llvm.objectsize.i64"] = &ObjectSize;
Optimizations["__memcpy_chk"] = &MemCpyChk;
Optimizations["__memset_chk"] = &MemSetChk;
Optimizations["__memmove_chk"] = &MemMoveChk;