mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-03 13:31:05 +00:00
CodeGen: Canonicalize access to function attributes, NFC
Canonicalize access to function attributes to use the simpler API. getAttributes().getAttribute(AttributeSet::FunctionIndex, Kind) => getFnAttribute(Kind) getAttributes().hasAttribute(AttributeSet::FunctionIndex, Kind) => hasFnAttribute(Kind) Also, add `Function::getFnStackAlignment()`, and canonicalize: getAttributes().getStackAlignment(AttributeSet::FunctionIndex) => getFnStackAlignment() git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229208 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6a50342499
commit
9de77c7eca
@ -218,6 +218,11 @@ public:
|
|||||||
return AttributeSets.getAttribute(AttributeSet::FunctionIndex, Kind);
|
return AttributeSets.getAttribute(AttributeSet::FunctionIndex, Kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Return the stack alignment for the function.
|
||||||
|
unsigned getFnStackAlignment() const {
|
||||||
|
return AttributeSets.getStackAlignment(AttributeSet::FunctionIndex);
|
||||||
|
}
|
||||||
|
|
||||||
/// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
|
/// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
|
||||||
/// to use during code generation.
|
/// to use during code generation.
|
||||||
bool hasGC() const;
|
bool hasGC() const;
|
||||||
|
@ -601,8 +601,7 @@ static bool ProfitableToMerge(MachineBasicBlock *MBB1,
|
|||||||
// instructions that would be deleted in the merge.
|
// instructions that would be deleted in the merge.
|
||||||
MachineFunction *MF = MBB1->getParent();
|
MachineFunction *MF = MBB1->getParent();
|
||||||
if (EffectiveTailLen >= 2 &&
|
if (EffectiveTailLen >= 2 &&
|
||||||
MF->getFunction()->getAttributes().
|
MF->getFunction()->hasFnAttribute(Attribute::OptimizeForSize) &&
|
||||||
hasAttribute(AttributeSet::FunctionIndex, Attribute::OptimizeForSize) &&
|
|
||||||
(I1 == MBB1->begin() || I2 == MBB2->begin()))
|
(I1 == MBB1->begin() || I2 == MBB2->begin()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -217,8 +217,7 @@ bool CodeGenPrepare::runOnFunction(Function &F) {
|
|||||||
DominatorTreeWrapperPass *DTWP =
|
DominatorTreeWrapperPass *DTWP =
|
||||||
getAnalysisIfAvailable<DominatorTreeWrapperPass>();
|
getAnalysisIfAvailable<DominatorTreeWrapperPass>();
|
||||||
DT = DTWP ? &DTWP->getDomTree() : nullptr;
|
DT = DTWP ? &DTWP->getDomTree() : nullptr;
|
||||||
OptSize = F.getAttributes().hasAttribute(AttributeSet::FunctionIndex,
|
OptSize = F.hasFnAttribute(Attribute::OptimizeForSize);
|
||||||
Attribute::OptimizeForSize);
|
|
||||||
|
|
||||||
/// This optimization identifies DIV instructions that can be
|
/// This optimization identifies DIV instructions that can be
|
||||||
/// profitably bypassed and carried out with a shorter, faster divide.
|
/// profitably bypassed and carried out with a shorter, faster divide.
|
||||||
|
@ -1058,8 +1058,7 @@ void MachineBlockPlacement::buildCFGChains(MachineFunction &F) {
|
|||||||
// exclusively on the loop info here so that we can align backedges in
|
// exclusively on the loop info here so that we can align backedges in
|
||||||
// unnatural CFGs and backedges that were introduced purely because of the
|
// unnatural CFGs and backedges that were introduced purely because of the
|
||||||
// loop rotations done during this layout pass.
|
// loop rotations done during this layout pass.
|
||||||
if (F.getFunction()->getAttributes().
|
if (F.getFunction()->hasFnAttribute(Attribute::OptimizeForSize))
|
||||||
hasAttribute(AttributeSet::FunctionIndex, Attribute::OptimizeForSize))
|
|
||||||
return;
|
return;
|
||||||
if (FunctionChain.begin() == FunctionChain.end())
|
if (FunctionChain.begin() == FunctionChain.end())
|
||||||
return; // Empty chain.
|
return; // Empty chain.
|
||||||
|
@ -413,8 +413,7 @@ bool MachineCombiner::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
Traces = &getAnalysis<MachineTraceMetrics>();
|
Traces = &getAnalysis<MachineTraceMetrics>();
|
||||||
MinInstr = 0;
|
MinInstr = 0;
|
||||||
|
|
||||||
OptSize = MF.getFunction()->getAttributes().hasAttribute(
|
OptSize = MF.getFunction()->hasFnAttribute(Attribute::OptimizeForSize);
|
||||||
AttributeSet::FunctionIndex, Attribute::OptimizeForSize);
|
|
||||||
|
|
||||||
DEBUG(dbgs() << getPassName() << ": " << MF.getName() << '\n');
|
DEBUG(dbgs() << getPassName() << ": " << MF.getName() << '\n');
|
||||||
if (!TII->useMachineCombiner()) {
|
if (!TII->useMachineCombiner()) {
|
||||||
|
@ -67,17 +67,14 @@ MachineFunction::MachineFunction(const Function *F, const TargetMachine &TM,
|
|||||||
STI->getFrameLowering()->isStackRealignable(),
|
STI->getFrameLowering()->isStackRealignable(),
|
||||||
!F->hasFnAttribute("no-realign-stack"));
|
!F->hasFnAttribute("no-realign-stack"));
|
||||||
|
|
||||||
if (Fn->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
|
if (Fn->hasFnAttribute(Attribute::StackAlignment))
|
||||||
Attribute::StackAlignment))
|
FrameInfo->ensureMaxAlignment(Fn->getFnStackAlignment());
|
||||||
FrameInfo->ensureMaxAlignment(Fn->getAttributes().
|
|
||||||
getStackAlignment(AttributeSet::FunctionIndex));
|
|
||||||
|
|
||||||
ConstantPool = new (Allocator) MachineConstantPool(TM);
|
ConstantPool = new (Allocator) MachineConstantPool(TM);
|
||||||
Alignment = STI->getTargetLowering()->getMinFunctionAlignment();
|
Alignment = STI->getTargetLowering()->getMinFunctionAlignment();
|
||||||
|
|
||||||
// FIXME: Shouldn't use pref alignment if explicit alignment is set on Fn.
|
// FIXME: Shouldn't use pref alignment if explicit alignment is set on Fn.
|
||||||
if (!Fn->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
|
if (!Fn->hasFnAttribute(Attribute::OptimizeForSize))
|
||||||
Attribute::OptimizeForSize))
|
|
||||||
Alignment = std::max(Alignment,
|
Alignment = std::max(Alignment,
|
||||||
STI->getTargetLowering()->getPrefFunctionAlignment());
|
STI->getTargetLowering()->getPrefFunctionAlignment());
|
||||||
|
|
||||||
|
@ -403,12 +403,9 @@ namespace {
|
|||||||
DAGCombiner(SelectionDAG &D, AliasAnalysis &A, CodeGenOpt::Level OL)
|
DAGCombiner(SelectionDAG &D, AliasAnalysis &A, CodeGenOpt::Level OL)
|
||||||
: DAG(D), TLI(D.getTargetLoweringInfo()), Level(BeforeLegalizeTypes),
|
: DAG(D), TLI(D.getTargetLoweringInfo()), Level(BeforeLegalizeTypes),
|
||||||
OptLevel(OL), LegalOperations(false), LegalTypes(false), AA(A) {
|
OptLevel(OL), LegalOperations(false), LegalTypes(false), AA(A) {
|
||||||
AttributeSet FnAttrs =
|
auto *F = DAG.getMachineFunction().getFunction();
|
||||||
DAG.getMachineFunction().getFunction()->getAttributes();
|
ForCodeSize = F->hasFnAttribute(Attribute::OptimizeForSize) ||
|
||||||
ForCodeSize =
|
F->hasFnAttribute(Attribute::MinSize);
|
||||||
FnAttrs.hasAttribute(AttributeSet::FunctionIndex,
|
|
||||||
Attribute::OptimizeForSize) ||
|
|
||||||
FnAttrs.hasAttribute(AttributeSet::FunctionIndex, Attribute::MinSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs the dag combiner on all nodes in the work list
|
/// Runs the dag combiner on all nodes in the work list
|
||||||
@ -1184,9 +1181,7 @@ void DAGCombiner::Run(CombineLevel AtLevel) {
|
|||||||
LegalTypes = Level >= AfterLegalizeTypes;
|
LegalTypes = Level >= AfterLegalizeTypes;
|
||||||
|
|
||||||
// Early exit if this basic block is in an optnone function.
|
// Early exit if this basic block is in an optnone function.
|
||||||
AttributeSet FnAttrs =
|
if (DAG.getMachineFunction().getFunction()->hasFnAttribute(
|
||||||
DAG.getMachineFunction().getFunction()->getAttributes();
|
|
||||||
if (FnAttrs.hasAttribute(AttributeSet::FunctionIndex,
|
|
||||||
Attribute::OptimizeNone))
|
Attribute::OptimizeNone))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -9955,8 +9950,8 @@ bool DAGCombiner::MergeStoresOfConstantsOrVecElts(
|
|||||||
bool DAGCombiner::MergeConsecutiveStores(StoreSDNode* St) {
|
bool DAGCombiner::MergeConsecutiveStores(StoreSDNode* St) {
|
||||||
EVT MemVT = St->getMemoryVT();
|
EVT MemVT = St->getMemoryVT();
|
||||||
int64_t ElementSizeBytes = MemVT.getSizeInBits()/8;
|
int64_t ElementSizeBytes = MemVT.getSizeInBits()/8;
|
||||||
bool NoVectors = DAG.getMachineFunction().getFunction()->getAttributes().
|
bool NoVectors = DAG.getMachineFunction().getFunction()->hasFnAttribute(
|
||||||
hasAttribute(AttributeSet::FunctionIndex, Attribute::NoImplicitFloat);
|
Attribute::NoImplicitFloat);
|
||||||
|
|
||||||
// Don't merge vectors into wider inputs.
|
// Don't merge vectors into wider inputs.
|
||||||
if (MemVT.isVector() || !MemVT.isSimple())
|
if (MemVT.isVector() || !MemVT.isSimple())
|
||||||
|
@ -3971,9 +3971,7 @@ static SDValue getMemcpyLoadsAndStores(SelectionDAG &DAG, SDLoc dl,
|
|||||||
bool DstAlignCanChange = false;
|
bool DstAlignCanChange = false;
|
||||||
MachineFunction &MF = DAG.getMachineFunction();
|
MachineFunction &MF = DAG.getMachineFunction();
|
||||||
MachineFrameInfo *MFI = MF.getFrameInfo();
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||||
bool OptSize =
|
bool OptSize = MF.getFunction()->hasFnAttribute(Attribute::OptimizeForSize);
|
||||||
MF.getFunction()->getAttributes().
|
|
||||||
hasAttribute(AttributeSet::FunctionIndex, Attribute::OptimizeForSize);
|
|
||||||
FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Dst);
|
FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Dst);
|
||||||
if (FI && !MFI->isFixedObjectIndex(FI->getIndex()))
|
if (FI && !MFI->isFixedObjectIndex(FI->getIndex()))
|
||||||
DstAlignCanChange = true;
|
DstAlignCanChange = true;
|
||||||
@ -4086,8 +4084,7 @@ static SDValue getMemmoveLoadsAndStores(SelectionDAG &DAG, SDLoc dl,
|
|||||||
bool DstAlignCanChange = false;
|
bool DstAlignCanChange = false;
|
||||||
MachineFunction &MF = DAG.getMachineFunction();
|
MachineFunction &MF = DAG.getMachineFunction();
|
||||||
MachineFrameInfo *MFI = MF.getFrameInfo();
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||||
bool OptSize = MF.getFunction()->getAttributes().
|
bool OptSize = MF.getFunction()->hasFnAttribute(Attribute::OptimizeForSize);
|
||||||
hasAttribute(AttributeSet::FunctionIndex, Attribute::OptimizeForSize);
|
|
||||||
FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Dst);
|
FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Dst);
|
||||||
if (FI && !MFI->isFixedObjectIndex(FI->getIndex()))
|
if (FI && !MFI->isFixedObjectIndex(FI->getIndex()))
|
||||||
DstAlignCanChange = true;
|
DstAlignCanChange = true;
|
||||||
@ -4181,8 +4178,7 @@ static SDValue getMemsetStores(SelectionDAG &DAG, SDLoc dl,
|
|||||||
bool DstAlignCanChange = false;
|
bool DstAlignCanChange = false;
|
||||||
MachineFunction &MF = DAG.getMachineFunction();
|
MachineFunction &MF = DAG.getMachineFunction();
|
||||||
MachineFrameInfo *MFI = MF.getFrameInfo();
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||||
bool OptSize = MF.getFunction()->getAttributes().
|
bool OptSize = MF.getFunction()->hasFnAttribute(Attribute::OptimizeForSize);
|
||||||
hasAttribute(AttributeSet::FunctionIndex, Attribute::OptimizeForSize);
|
|
||||||
FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Dst);
|
FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Dst);
|
||||||
if (FI && !MFI->isFixedObjectIndex(FI->getIndex()))
|
if (FI && !MFI->isFixedObjectIndex(FI->getIndex()))
|
||||||
DstAlignCanChange = true;
|
DstAlignCanChange = true;
|
||||||
|
@ -4591,8 +4591,7 @@ static SDValue ExpandPowI(SDLoc DL, SDValue LHS, SDValue RHS,
|
|||||||
return DAG.getConstantFP(1.0, LHS.getValueType());
|
return DAG.getConstantFP(1.0, LHS.getValueType());
|
||||||
|
|
||||||
const Function *F = DAG.getMachineFunction().getFunction();
|
const Function *F = DAG.getMachineFunction().getFunction();
|
||||||
if (!F->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
|
if (!F->hasFnAttribute(Attribute::OptimizeForSize) ||
|
||||||
Attribute::OptimizeForSize) ||
|
|
||||||
// If optimizing for size, don't insert too many multiplies. This
|
// If optimizing for size, don't insert too many multiplies. This
|
||||||
// inserts up to 5 multiplies.
|
// inserts up to 5 multiplies.
|
||||||
countPopulation(Val) + Log2_32(Val) < 7) {
|
countPopulation(Val) + Log2_32(Val) < 7) {
|
||||||
|
@ -90,8 +90,7 @@ bool StackProtector::runOnFunction(Function &Fn) {
|
|||||||
DT = DTWP ? &DTWP->getDomTree() : nullptr;
|
DT = DTWP ? &DTWP->getDomTree() : nullptr;
|
||||||
TLI = TM->getSubtargetImpl(Fn)->getTargetLowering();
|
TLI = TM->getSubtargetImpl(Fn)->getTargetLowering();
|
||||||
|
|
||||||
Attribute Attr = Fn.getAttributes().getAttribute(
|
Attribute Attr = Fn.getFnAttribute("stack-protector-buffer-size");
|
||||||
AttributeSet::FunctionIndex, "stack-protector-buffer-size");
|
|
||||||
if (Attr.isStringAttribute() &&
|
if (Attr.isStringAttribute() &&
|
||||||
Attr.getValueAsString().getAsInteger(10, SSPBufferSize))
|
Attr.getValueAsString().getAsInteger(10, SSPBufferSize))
|
||||||
return false; // Invalid integer string
|
return false; // Invalid integer string
|
||||||
@ -201,15 +200,12 @@ bool StackProtector::HasAddressTaken(const Instruction *AI) {
|
|||||||
bool StackProtector::RequiresStackProtector() {
|
bool StackProtector::RequiresStackProtector() {
|
||||||
bool Strong = false;
|
bool Strong = false;
|
||||||
bool NeedsProtector = false;
|
bool NeedsProtector = false;
|
||||||
if (F->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
|
if (F->hasFnAttribute(Attribute::StackProtectReq)) {
|
||||||
Attribute::StackProtectReq)) {
|
|
||||||
NeedsProtector = true;
|
NeedsProtector = true;
|
||||||
Strong = true; // Use the same heuristic as strong to determine SSPLayout
|
Strong = true; // Use the same heuristic as strong to determine SSPLayout
|
||||||
} else if (F->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
|
} else if (F->hasFnAttribute(Attribute::StackProtectStrong))
|
||||||
Attribute::StackProtectStrong))
|
|
||||||
Strong = true;
|
Strong = true;
|
||||||
else if (!F->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
|
else if (!F->hasFnAttribute(Attribute::StackProtect))
|
||||||
Attribute::StackProtect))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (const BasicBlock &BB : *F) {
|
for (const BasicBlock &BB : *F) {
|
||||||
|
@ -560,8 +560,7 @@ TailDuplicatePass::shouldTailDuplicate(const MachineFunction &MF,
|
|||||||
// compensate for the duplication.
|
// compensate for the duplication.
|
||||||
unsigned MaxDuplicateCount;
|
unsigned MaxDuplicateCount;
|
||||||
if (TailDuplicateSize.getNumOccurrences() == 0 &&
|
if (TailDuplicateSize.getNumOccurrences() == 0 &&
|
||||||
MF.getFunction()->getAttributes().
|
MF.getFunction()->hasFnAttribute(Attribute::OptimizeForSize))
|
||||||
hasAttribute(AttributeSet::FunctionIndex, Attribute::OptimizeForSize))
|
|
||||||
MaxDuplicateCount = 1;
|
MaxDuplicateCount = 1;
|
||||||
else
|
else
|
||||||
MaxDuplicateCount = TailDuplicateSize;
|
MaxDuplicateCount = TailDuplicateSize;
|
||||||
|
Loading…
Reference in New Issue
Block a user