Skip to content

Commit 67ba729

Browse files
authored
Create shadows for constant, non internal globals (rust-lang#693)
1 parent 4eaa5ef commit 67ba729

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

enzyme/Enzyme/GradientUtils.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4090,8 +4090,16 @@ Value *GradientUtils::invertPointerM(Value *const oval, IRBuilder<> &BuilderM,
40904090
}
40914091

40924092
// Create global variable locally if not externally visible
4093+
// If a variable is constant, for forward mode it will also
4094+
// only be read, so invert initializing is fine.
4095+
// For reverse mode, any floats will be +='d into, but never
4096+
// read, and any pointers will be used as expected. The never
4097+
// read means even if two globals for floats, that's fine.
4098+
// As long as the pointers point to equivalent places (which
4099+
// they should from the same initialization), it is also ok.
40934100
if (arg->hasInternalLinkage() || arg->hasPrivateLinkage() ||
4094-
(arg->hasExternalLinkage() && arg->hasInitializer())) {
4101+
(arg->hasExternalLinkage() && arg->hasInitializer()) ||
4102+
arg->isConstant()) {
40954103
Type *elemTy = arg->getType()->getPointerElementType();
40964104
Type *type = getShadowType(elemTy);
40974105
IRBuilder<> B(inversionAllocs);

0 commit comments

Comments
 (0)