Skip to content

Commit

Permalink
Merged master:c73966c2f792 into amd-gfx:98acc6627628
Browse files Browse the repository at this point in the history
Local branch amd-gfx 98acc66 Merged master:b9306fd042ce into amd-gfx:242c36a54a72
Remote branch master c73966c Improve stack object printing. NFC.
  • Loading branch information
Sw authored and Sw committed Jun 28, 2020
2 parents 98acc66 + c73966c commit c667b86
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class IdentifierNamingCheck final : public RenamerClangTidyCheck {

} // namespace readability
template <>
struct ::clang::tidy::OptionEnumMapping<
struct OptionEnumMapping<
readability::IdentifierNamingCheck::CaseType> {
static llvm::ArrayRef<
std::pair<readability::IdentifierNamingCheck::CaseType, StringRef>>
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/MachineFrameInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ class MachineFrameInfo {
BitVector getPristineRegs(const MachineFunction &MF) const;

/// Used by the MachineFunction printer to print information about
/// stack objects. Implemented in MachineFunction.cpp.
/// stack objects.
void print(const MachineFunction &MF, raw_ostream &OS) const;

/// dump - Print the function to stderr.
Expand Down
14 changes: 10 additions & 4 deletions llvm/lib/CodeGen/MachineFrameInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,32 +210,38 @@ void MachineFrameInfo::computeMaxCallFrameSize(const MachineFunction &MF) {
}

void MachineFrameInfo::print(const MachineFunction &MF, raw_ostream &OS) const{
if (Objects.empty()) return;

OS << "MF name: " << MF.getName() << "\n";
if (Objects.empty()) {
OS << "No stack objects.\n";
return;
}
const TargetFrameLowering *FI = MF.getSubtarget().getFrameLowering();
int ValOffset = (FI ? FI->getOffsetOfLocalArea() : 0);

OS << "NumFixedObjects=" << static_cast<unsigned>(NumFixedObjects) << "\n";

OS << "Frame Objects:\n";

for (unsigned i = 0, e = Objects.size(); i != e; ++i) {
const StackObject &SO = Objects[i];
OS << " fi#" << (int)(i-NumFixedObjects) << ": ";

if (SO.StackID != 0)
OS << "id=" << static_cast<unsigned>(SO.StackID) << ' ';
OS << "stackid=" << static_cast<unsigned>(SO.StackID) << ", ";

if (SO.Size == ~0ULL) {
OS << "dead\n";
continue;
}
OS << "isSplitSplot=" << static_cast<bool>(SO.isSpillSlot) << ", ";
if (SO.Size == 0)
OS << "variable sized";
else
OS << "size=" << SO.Size;
OS << ", align=" << SO.Alignment.value();

if (i < NumFixedObjects)
OS << ", fixed";
OS << ", fixed objects:";
if (i < NumFixedObjects || SO.SPOffset != -1) {
int64_t Off = SO.SPOffset - ValOffset;
OS << ", at location [SP";
Expand Down
35 changes: 29 additions & 6 deletions llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/InitializePasses.h"
Expand Down Expand Up @@ -254,9 +255,25 @@ static unsigned ComputeSpeculationCost(const Instruction *I,
bool SpeculativeExecutionPass::considerHoistingFromTo(
BasicBlock &FromBlock, BasicBlock &ToBlock) {
SmallPtrSet<const Instruction *, 8> NotHoisted;
const auto AllPrecedingUsesFromBlockHoisted = [&NotHoisted](User *U) {
for (Value* V : U->operand_values()) {
if (Instruction *I = dyn_cast<Instruction>(V)) {
const auto AllPrecedingUsesFromBlockHoisted = [&NotHoisted](const User *U) {
// Debug variable has special operand to check it's not hoisted.
if (const auto *DVI = dyn_cast<DbgVariableIntrinsic>(U)) {
if (const auto *I =
dyn_cast_or_null<Instruction>(DVI->getVariableLocation()))
if (NotHoisted.count(I) == 0)
return true;
return false;
}

// Usially debug label instrinsic corresponds to label in LLVM IR. In these
// cases we should not move it here.
// TODO: Possible special processing needed to detect it is related to a
// hoisted instruction.
if (isa<DbgLabelInst>(U))
return false;

for (const Value *V : U->operand_values()) {
if (const Instruction *I = dyn_cast<Instruction>(V)) {
if (NotHoisted.count(I) > 0)
return false;
}
Expand All @@ -265,17 +282,23 @@ bool SpeculativeExecutionPass::considerHoistingFromTo(
};

unsigned TotalSpeculationCost = 0;
for (auto& I : FromBlock) {
unsigned NotHoistedInstCount = 0;
for (const auto &I : FromBlock) {
const unsigned Cost = ComputeSpeculationCost(&I, *TTI);
if (Cost != UINT_MAX && isSafeToSpeculativelyExecute(&I) &&
AllPrecedingUsesFromBlockHoisted(&I)) {
TotalSpeculationCost += Cost;
if (TotalSpeculationCost > SpecExecMaxSpeculationCost)
return false; // too much to hoist
} else {
NotHoisted.insert(&I);
if (NotHoisted.size() > SpecExecMaxNotHoisted)
// If the instruction cannot be hoisted but has zero cost suppose it's
// a special case e.g. debug info instrinsics that should not be counted
// for threshold.
if (Cost)
NotHoistedInstCount++;
if (NotHoistedInstCount > SpecExecMaxNotHoisted)
return false; // too much left behind
NotHoisted.insert(&I);
}
}

Expand Down
18 changes: 9 additions & 9 deletions llvm/test/CodeGen/X86/dagcombine-cse.ll
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=i386-apple-darwin -mattr=+sse2 | FileCheck %s --check-prefix=X32
; RUN: llc < %s -mtriple=i386-apple-darwin -mattr=+sse2 | FileCheck %s --check-prefix=X86
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mattr=+sse2 | FileCheck %s --check-prefix=X64

define i32 @t(i8* %ref_frame_ptr, i32 %ref_frame_stride, i32 %idxX, i32 %idxY) nounwind {
; X32-LABEL: t:
; X32: ## %bb.0: ## %entry
; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
; X32-NEXT: imull {{[0-9]+}}(%esp), %ecx
; X32-NEXT: addl {{[0-9]+}}(%esp), %ecx
; X32-NEXT: movl (%eax,%ecx), %eax
; X32-NEXT: retl
; X86-LABEL: t:
; X86: ## %bb.0: ## %entry
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
; X86-NEXT: imull {{[0-9]+}}(%esp), %ecx
; X86-NEXT: addl {{[0-9]+}}(%esp), %ecx
; X86-NEXT: movl (%eax,%ecx), %eax
; X86-NEXT: retl
;
; X64-LABEL: t:
; X64: ## %bb.0: ## %entry
Expand Down
63 changes: 63 additions & 0 deletions llvm/test/Transforms/SpeculativeExecution/PR46267.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
; RUN: opt < %s -S -speculative-execution | FileCheck %s
; RUN: opt < %s -S -passes='speculative-execution' | FileCheck %s

define void @f(i32 %i) {
entry:
; CHECK-LABEL: @f(
; CHECK: %a2 = add i32 %i, 0
; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %a2
br i1 undef, label %land.rhs, label %land.end

land.rhs: ; preds = %entry
; CHECK: land.rhs:
; CHECK-NEXT: call void @llvm.dbg.label
; CHECK-NEXT: %x = alloca i32, align 4
; CHECK-NEXT: call void @llvm.dbg.addr(metadata i32* %x
; CHECK-NEXT: %y = alloca i32, align 4
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i32* %y
; CHECK-NEXT: %a0 = load i32, i32* undef, align 1
; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %a0
call void @llvm.dbg.label(metadata !11), !dbg !10
%x = alloca i32, align 4
call void @llvm.dbg.addr(metadata i32* %x, metadata !12, metadata !DIExpression()), !dbg !10
%y = alloca i32, align 4
call void @llvm.dbg.declare(metadata i32* %y, metadata !14, metadata !DIExpression()), !dbg !10

%a0 = load i32, i32* undef, align 1
call void @llvm.dbg.value(metadata i32 %a0, metadata !9, metadata !DIExpression()), !dbg !10

%a2 = add i32 %i, 0
call void @llvm.dbg.value(metadata i32 %a2, metadata !13, metadata !DIExpression()), !dbg !10

br label %land.end

land.end: ; preds = %land.rhs, %entry
ret void
}

; Function Attrs: nounwind readnone speculatable willreturn
declare void @llvm.dbg.value(metadata, metadata, metadata) #1
declare void @llvm.dbg.label(metadata)
declare void @llvm.dbg.declare(metadata, metadata, metadata)
declare void @llvm.dbg.addr(metadata, metadata, metadata)

attributes #1 = { nounwind readnone speculatable willreturn }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!5}

!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "foo.c", directory: "/bar")
!2 = !{}
!3 = !{!4}
!4 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_signed)
!5 = !{i32 2, !"Debug Info Version", i32 3}
!6 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !7, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
!7 = !DISubroutineType(types: !8)
!8 = !{null}
!9 = !DILocalVariable(name: "a0", scope: !6, file: !1, line: 3, type: !4)
!10 = !DILocation(line: 0, scope: !6)
!11 = !DILabel(scope: !6, name: "label", file: !1, line: 1)
!12 = !DILocalVariable(name: "x", scope: !6, file: !1, line: 3, type: !4)
!13 = !DILocalVariable(name: "a2", scope: !6, file: !1, line: 3, type: !4)
!14 = !DILocalVariable(name: "y", scope: !6, file: !1, line: 3, type: !4)

0 comments on commit c667b86

Please sign in to comment.