<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
location. At compile-time, the code generator generates information to allow
-the runtime to find the pointer at GC safe points.
-</p>
+the runtime to find the pointer at GC safe points. The '<tt>llvm.gcroot</tt>'
+intrinsic may only be used in a function which <a href="#gc">specifies a GC
+algorithm</a>.</p>
</div>
<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
instruction, but may be replaced with substantially more complex code by the
-garbage collector runtime, as needed.</p>
+garbage collector runtime, as needed. The '<tt>llvm.gcread</tt>' intrinsic
+may only be used in a function which <a href="#gc">specifies a GC
+algorithm</a>.</p>
</div>
<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
instruction, but may be replaced with substantially more complex code by the
-garbage collector runtime, as needed.</p>
+garbage collector runtime, as needed. The '<tt>llvm.gcwrite</tt>' intrinsic
+may only be used in a function which <a href="#gc">specifies a GC
+algorithm</a>.</p>
</div>
switch (ID) {
default:
break;
- case Intrinsic::gcroot: {
- Type *PtrTy = PointerType::getUnqual(Type::Int8Ty),
- *PtrPtrTy = PointerType::getUnqual(PtrTy);
- Assert1(CI.getOperand(1)->getType() == PtrPtrTy,
- "Intrinsic parameter #1 is not i8**.", &CI);
- Assert1(CI.getOperand(2)->getType() == PtrTy,
- "Intrinsic parameter #2 is not i8*.", &CI);
- Assert1(
- isa<AllocaInst>(IntrinsicInst::StripPointerCasts(CI.getOperand(1))),
- "llvm.gcroot parameter #1 must be an alloca.",
- &CI);
- Assert1(isa<Constant>(CI.getOperand(2)),
- "llvm.gcroot parameter #2 must be a constant.", &CI);
- } break;
- case Intrinsic::gcwrite: {
- Type *PtrTy = PointerType::getUnqual(Type::Int8Ty),
- *PtrPtrTy = PointerType::getUnqual(PtrTy);
- Assert1(CI.getOperand(1)->getType() == PtrTy,
- "Intrinsic parameter #1 is not a i8*.", &CI);
- Assert1(CI.getOperand(2)->getType() == PtrTy,
- "Intrinsic parameter #2 is not a i8*.", &CI);
- Assert1(CI.getOperand(3)->getType() == PtrPtrTy,
- "Intrinsic parameter #3 is not a i8**.", &CI);
- } break;
+ case Intrinsic::gcroot:
+ case Intrinsic::gcwrite:
case Intrinsic::gcread: {
Type *PtrTy = PointerType::getUnqual(Type::Int8Ty),
*PtrPtrTy = PointerType::getUnqual(PtrTy);
- Assert1(CI.getOperand(1)->getType() == PtrTy,
- "Intrinsic parameter #1 is not a i8*.", &CI);
- Assert1(CI.getOperand(2)->getType() == PtrPtrTy,
- "Intrinsic parameter #2 is not a i8**.", &CI);
+
+ switch (ID) {
+ default:
+ break;
+ case Intrinsic::gcroot:
+ Assert1(CI.getOperand(1)->getType() == PtrPtrTy,
+ "Intrinsic parameter #1 is not i8**.", &CI);
+ Assert1(CI.getOperand(2)->getType() == PtrTy,
+ "Intrinsic parameter #2 is not i8*.", &CI);
+ Assert1(isa<AllocaInst>(
+ IntrinsicInst::StripPointerCasts(CI.getOperand(1))),
+ "llvm.gcroot parameter #1 must be an alloca.", &CI);
+ Assert1(isa<Constant>(CI.getOperand(2)),
+ "llvm.gcroot parameter #2 must be a constant.", &CI);
+ break;
+ case Intrinsic::gcwrite:
+ Assert1(CI.getOperand(1)->getType() == PtrTy,
+ "Intrinsic parameter #1 is not a i8*.", &CI);
+ Assert1(CI.getOperand(2)->getType() == PtrTy,
+ "Intrinsic parameter #2 is not a i8*.", &CI);
+ Assert1(CI.getOperand(3)->getType() == PtrPtrTy,
+ "Intrinsic parameter #3 is not a i8**.", &CI);
+ break;
+ case Intrinsic::gcread:
+ Assert1(CI.getOperand(1)->getType() == PtrTy,
+ "Intrinsic parameter #1 is not a i8*.", &CI);
+ Assert1(CI.getOperand(2)->getType() == PtrPtrTy,
+ "Intrinsic parameter #2 is not a i8**.", &CI);
+ break;
+ }
+
+ Assert1(CI.getParent()->getParent()->hasCollector(),
+ "Enclosing function does not specify a collector algorithm.",
+ &CI);
} break;
case Intrinsic::init_trampoline:
Assert1(isa<Function>(IntrinsicInst::StripPointerCasts(CI.getOperand(2))),