mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-27 14:24:40 +00:00
further clarify alignment of globals, fix instcombine
to not increase the alignment of globals with an assigned alignment and section. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@102476 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -855,10 +855,11 @@ define i32 @main() { <i>; i32()* </i>
|
|||||||
of 2. If not present, or if the alignment is set to zero, the alignment of
|
of 2. If not present, or if the alignment is set to zero, the alignment of
|
||||||
the global is set by the target to whatever it feels convenient. If an
|
the global is set by the target to whatever it feels convenient. If an
|
||||||
explicit alignment is specified, the global is forced to have exactly that
|
explicit alignment is specified, the global is forced to have exactly that
|
||||||
alignment. Targets are not allowed to over-align the global in cases where
|
alignment. Targets and optimizers are not allowed to over-align the global
|
||||||
it is observable: for example, overaligning a global is observable if it has
|
if the global has an assigned section. In this case, the extra alignment
|
||||||
an assigned section and higher alignment could cause holes between
|
could be observable: for example, code could assume that the globals are
|
||||||
consequtive globals.</p>
|
densely packed in their section and try to iterate over them as an array,
|
||||||
|
alignment padding would break this iteration.</p>
|
||||||
|
|
||||||
<p>For example, the following defines a global in a numbered address space with
|
<p>For example, the following defines a global in a numbered address space with
|
||||||
an initializer, section, and alignment:</p>
|
an initializer, section, and alignment:</p>
|
||||||
|
@ -59,29 +59,32 @@ static unsigned EnforceKnownAlignment(Value *V,
|
|||||||
// Treat this like a bitcast.
|
// Treat this like a bitcast.
|
||||||
return EnforceKnownAlignment(U->getOperand(0), Align, PrefAlign);
|
return EnforceKnownAlignment(U->getOperand(0), Align, PrefAlign);
|
||||||
}
|
}
|
||||||
break;
|
return Align;
|
||||||
|
}
|
||||||
|
case Instruction::Alloca: {
|
||||||
|
AllocaInst *AI = cast<AllocaInst>(V);
|
||||||
|
// If there is a requested alignment and if this is an alloca, round up.
|
||||||
|
if (AI->getAlignment() >= PrefAlign)
|
||||||
|
return AI->getAlignment();
|
||||||
|
AI->setAlignment(PrefAlign);
|
||||||
|
return PrefAlign;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
|
if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
|
||||||
// If there is a large requested alignment and we can, bump up the alignment
|
// If there is a large requested alignment and we can, bump up the alignment
|
||||||
// of the global.
|
// of the global.
|
||||||
if (!GV->isDeclaration()) {
|
if (GV->isDeclaration()) return Align;
|
||||||
|
|
||||||
if (GV->getAlignment() >= PrefAlign)
|
if (GV->getAlignment() >= PrefAlign)
|
||||||
Align = GV->getAlignment();
|
return GV->getAlignment();
|
||||||
else {
|
// We can only increase the alignment of the global if it has no alignment
|
||||||
|
// specified or if it is not assigned a section. If it is assigned a
|
||||||
|
// section, the global could be densely packed with other objects in the
|
||||||
|
// section, increasing the alignment could cause padding issues.
|
||||||
|
if (!GV->hasSection() || GV->getAlignment() == 0)
|
||||||
GV->setAlignment(PrefAlign);
|
GV->setAlignment(PrefAlign);
|
||||||
Align = PrefAlign;
|
return GV->getAlignment();
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (AllocaInst *AI = dyn_cast<AllocaInst>(V)) {
|
|
||||||
// If there is a requested alignment and if this is an alloca, round up.
|
|
||||||
if (AI->getAlignment() >= PrefAlign)
|
|
||||||
Align = AI->getAlignment();
|
|
||||||
else {
|
|
||||||
AI->setAlignment(PrefAlign);
|
|
||||||
Align = PrefAlign;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Align;
|
return Align;
|
||||||
|
Reference in New Issue
Block a user