Skip to content

Commit

Permalink
Merged master:7bc03f55539f into amd-gfx:c5a8d66d784a
Browse files Browse the repository at this point in the history
Local branch amd-gfx c5a8d66 Merged master:6fe6b29c294e into amd-gfx:49849cf359eb
Remote branch master 7bc03f5 [MachineOutliner][AArch64] WA for multiple stack fixup cases in MachineOutliner.
  • Loading branch information
Sw authored and Sw committed Aug 10, 2020
2 parents c5a8d66 + 7bc03f5 commit b2a0e72
Show file tree
Hide file tree
Showing 22 changed files with 2,086 additions and 247 deletions.
3 changes: 3 additions & 0 deletions compiler-rt/lib/msan/msan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ void __msan_dump_shadow(const void *x, uptr size) {
sptr __msan_test_shadow(const void *x, uptr size) {
if (!MEM_IS_APP(x)) return -1;
unsigned char *s = (unsigned char *)MEM_TO_SHADOW((uptr)x);
if (__sanitizer::mem_is_zero((const char *)s, size))
return -1;
// Slow path: loop through again to find the location.
for (uptr i = 0; i < size; ++i)
if (s[i])
return i;
Expand Down
16 changes: 6 additions & 10 deletions flang/lib/Parser/prescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void Prescanner::Statement() {
case LineClassification::Kind::CompilerDirective:
directiveSentinel_ = line.sentinel;
CHECK(InCompilerDirective());
BeginSourceLineAndAdvance();
BeginStatementAndAdvance();
if (inFixedForm_) {
CHECK(IsFixedFormCommentChar(*at_));
} else {
Expand Down Expand Up @@ -144,7 +144,7 @@ void Prescanner::Statement() {
}
break;
case LineClassification::Kind::Source:
BeginSourceLineAndAdvance();
BeginStatementAndAdvance();
if (inFixedForm_) {
LabelField(tokens);
} else if (skipLeadingAmpersand_) {
Expand Down Expand Up @@ -226,7 +226,7 @@ void Prescanner::Statement() {
TokenSequence Prescanner::TokenizePreprocessorDirective() {
CHECK(nextLine_ < limit_ && !inPreprocessorDirective_);
inPreprocessorDirective_ = true;
BeginSourceLineAndAdvance();
BeginStatementAndAdvance();
TokenSequence tokens;
while (NextToken(tokens)) {
}
Expand Down Expand Up @@ -497,20 +497,16 @@ bool Prescanner::NextToken(TokenSequence &tokens) {
} while (IsLegalInIdentifier(EmitCharAndAdvance(tokens, *at_)));
if (*at_ == '\'' || *at_ == '"') {
QuotedCharacterLiteral(tokens, start);
preventHollerith_ = false;
} else {
// Subtle: Don't misrecognize labeled DO statement label as Hollerith
// when the loop control variable starts with 'H'.
preventHollerith_ = true;
}
preventHollerith_ = false;
} else if (*at_ == '*') {
if (EmitCharAndAdvance(tokens, '*') == '*') {
EmitCharAndAdvance(tokens, '*');
} else {
// Subtle ambiguity:
// CHARACTER*2H declares H because *2 is a kind specifier
// DATAC/N*2H / is repeated Hollerith
preventHollerith_ = !slashInCurrentLine_;
preventHollerith_ = !slashInCurrentStatement_;
}
} else {
char ch{*at_};
Expand All @@ -530,7 +526,7 @@ bool Prescanner::NextToken(TokenSequence &tokens) {
// token comprises two characters
EmitCharAndAdvance(tokens, nch);
} else if (ch == '/') {
slashInCurrentLine_ = true;
slashInCurrentStatement_ = true;
}
}
tokens.CloseToken();
Expand Down
14 changes: 9 additions & 5 deletions flang/lib/Parser/prescan.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,20 @@ class Prescanner {
at_ = at;
column_ = 1;
tabInCurrentLine_ = false;
slashInCurrentLine_ = false;
preventHollerith_ = false;
delimiterNesting_ = 0;
}

void BeginSourceLineAndAdvance() {
BeginSourceLine(nextLine_);
NextLine();
}

void BeginStatementAndAdvance() {
BeginSourceLineAndAdvance();
slashInCurrentStatement_ = false;
preventHollerith_ = false;
delimiterNesting_ = 0;
}

Provenance GetProvenance(const char *sourceChar) const {
return startProvenance_ + (sourceChar - start_);
}
Expand Down Expand Up @@ -199,8 +203,8 @@ class Prescanner {
const char *at_{nullptr}; // next character to process; < nextLine_
int column_{1}; // card image column position of next character
bool tabInCurrentLine_{false};
bool slashInCurrentLine_{false};
bool preventHollerith_{false};
bool slashInCurrentStatement_{false};
bool preventHollerith_{false}; // CHARACTER*4HIMOM not Hollerith
bool inCharLiteral_{false};
bool inPreprocessorDirective_{false};

Expand Down
37 changes: 22 additions & 15 deletions flang/lib/Semantics/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,21 +871,28 @@ std::optional<Expr<SubscriptInteger>> ExpressionAnalyzer::TripletPart(

std::optional<Subscript> ExpressionAnalyzer::AnalyzeSectionSubscript(
const parser::SectionSubscript &ss) {
return std::visit(common::visitors{
[&](const parser::SubscriptTriplet &t) {
return std::make_optional<Subscript>(
Triplet{TripletPart(std::get<0>(t.t)),
TripletPart(std::get<1>(t.t)),
TripletPart(std::get<2>(t.t))});
},
[&](const auto &s) -> std::optional<Subscript> {
if (auto subscriptExpr{AsSubscript(Analyze(s))}) {
return Subscript{std::move(*subscriptExpr)};
} else {
return std::nullopt;
}
},
},
return std::visit(
common::visitors{
[&](const parser::SubscriptTriplet &t) -> std::optional<Subscript> {
const auto &lower{std::get<0>(t.t)};
const auto &upper{std::get<1>(t.t)};
const auto &stride{std::get<2>(t.t)};
auto result{Triplet{
TripletPart(lower), TripletPart(upper), TripletPart(stride)}};
if ((lower && !result.lower()) || (upper && !result.upper())) {
return std::nullopt;
} else {
return std::make_optional<Subscript>(result);
}
},
[&](const auto &s) -> std::optional<Subscript> {
if (auto subscriptExpr{AsSubscript(Analyze(s))}) {
return Subscript{std::move(*subscriptExpr)};
} else {
return std::nullopt;
}
},
},
ss.u);
}

Expand Down
14 changes: 14 additions & 0 deletions flang/test/Preprocessing/hollerith.f
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
! RUN: %f18 -E %s 2>&1 | FileCheck %s
! CHECK: character*1hi
! CHECK: dataa/1*1h /
! CHECK: datab/1*1h /
! CHECK: do1h=1,2
CHARACTER*1H I
CHARACTER*1 A,B
INTEGER H
DATA A/1*1H /
DATA B/
+1*1H /
DO1H =1,2
1 CONTINUE
END
7 changes: 7 additions & 0 deletions flang/test/Semantics/assign04.f90
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,10 @@ real function f9() result(r)
!ERROR: Assignment to subprogram 'f9' is not allowed
f9 = 1.0
end

!ERROR: No explicit type declared for 'n'
subroutine s10(a, n)
implicit none
real a(n)
a(1:n) = 0.0 ! should not get a second error here
end
10 changes: 10 additions & 0 deletions lldb/source/Commands/CommandObjectPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,16 @@ class CommandObjectPlatformInstall : public CommandObjectParsed {

~CommandObjectPlatformInstall() override = default;

void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
if (request.GetCursorIndex())
return;
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
}

bool DoExecute(Args &args, CommandReturnObject &result) override {
if (args.GetArgumentCount() != 2) {
result.AppendError("platform target-install takes two arguments");
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/functionalities/completion/TestCompletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ def test_frame_recognizer_delete(self):
self.runCmd("frame recognizer add -l py_class -s module_name -n recognizer_name")
self.check_completion_with_desc('frame recognizer delete ', [['0', 'py_class, module module_name, symbol recognizer_name']])

def test_platform_install_local_file(self):
self.complete_from_to('platform target-install main.cp', 'platform target-install main.cpp')

@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489")
def test_symbol_name(self):
self.build()
Expand Down
43 changes: 42 additions & 1 deletion llvm/lib/Analysis/ConstantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
Expand All @@ -42,6 +43,7 @@
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/IntrinsicsAMDGPU.h"
#include "llvm/IR/IntrinsicsARM.h"
#include "llvm/IR/IntrinsicsWebAssembly.h"
#include "llvm/IR/IntrinsicsX86.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/Type.h"
Expand Down Expand Up @@ -1469,6 +1471,11 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
case Intrinsic::arm_mve_vctp16:
case Intrinsic::arm_mve_vctp32:
case Intrinsic::arm_mve_vctp64:
// WebAssembly float semantics are always known
case Intrinsic::wasm_trunc_signed:
case Intrinsic::wasm_trunc_unsigned:
case Intrinsic::wasm_trunc_saturate_signed:
case Intrinsic::wasm_trunc_saturate_unsigned:
return true;

// Floating point operations cannot be folded in strictfp functions in
Expand Down Expand Up @@ -1861,11 +1868,45 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
return ConstantInt::get(Ty->getContext(), Val.bitcastToAPInt());
}

APFloat U = Op->getValueAPF();

if (IntrinsicID == Intrinsic::wasm_trunc_signed ||
IntrinsicID == Intrinsic::wasm_trunc_unsigned ||
IntrinsicID == Intrinsic::wasm_trunc_saturate_signed ||
IntrinsicID == Intrinsic::wasm_trunc_saturate_unsigned) {

bool Saturating = IntrinsicID == Intrinsic::wasm_trunc_saturate_signed ||
IntrinsicID == Intrinsic::wasm_trunc_saturate_unsigned;
bool Signed = IntrinsicID == Intrinsic::wasm_trunc_signed ||
IntrinsicID == Intrinsic::wasm_trunc_saturate_signed;

if (U.isNaN())
return Saturating ? ConstantInt::get(Ty, 0) : nullptr;

unsigned Width = Ty->getIntegerBitWidth();
APSInt Int(Width, !Signed);
bool IsExact = false;
APFloat::opStatus Status =
U.convertToInteger(Int, APFloat::rmTowardZero, &IsExact);

if (Status == APFloat::opOK || Status == APFloat::opInexact)
return ConstantInt::get(Ty, Int);

if (!Saturating)
return nullptr;

if (U.isNegative())
return Signed ? ConstantInt::get(Ty, APInt::getSignedMinValue(Width))
: ConstantInt::get(Ty, APInt::getMinValue(Width));
else
return Signed ? ConstantInt::get(Ty, APInt::getSignedMaxValue(Width))
: ConstantInt::get(Ty, APInt::getMaxValue(Width));
}

if (!Ty->isHalfTy() && !Ty->isFloatTy() && !Ty->isDoubleTy())
return nullptr;

// Use internal versions of these intrinsics.
APFloat U = Op->getValueAPF();

if (IntrinsicID == Intrinsic::nearbyint || IntrinsicID == Intrinsic::rint) {
U.roundToIntegral(APFloat::rmNearestTiesToEven);
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/VirtRegMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,18 +400,18 @@ void VirtRegRewriter::handleIdentityCopy(MachineInstr &MI) const {
/// after processing the last in the bundle. Does not update LiveIntervals
/// which we shouldn't need for this instruction anymore.
void VirtRegRewriter::expandCopyBundle(MachineInstr &MI) const {
if (!MI.isCopy())
if (!MI.isCopy() && !MI.isKill())
return;

if (MI.isBundledWithPred() && !MI.isBundledWithSucc()) {
SmallVector<MachineInstr *, 2> MIs({&MI});

// Only do this when the complete bundle is made out of COPYs.
// Only do this when the complete bundle is made out of COPYs and KILLs.
MachineBasicBlock &MBB = *MI.getParent();
for (MachineBasicBlock::reverse_instr_iterator I =
std::next(MI.getReverseIterator()), E = MBB.instr_rend();
I != E && I->isBundledWithSucc(); ++I) {
if (!I->isCopy())
if (!I->isCopy() && !I->isKill())
return;
MIs.push_back(&*I);
}
Expand Down
57 changes: 57 additions & 0 deletions llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6193,6 +6193,60 @@ outliner::OutlinedFunction AArch64InstrInfo::getOutliningCandidateInfo(
FrameID = MachineOutlinerNoLRSave;
} else {
SetCandidateCallInfo(MachineOutlinerDefault, 12);

// Bugzilla ID: 46767
// TODO: Check if fixing up the stack more than once is safe so we can
// outline these.
//
// An outline resulting in a caller that requires stack fixups at the
// callsite to a callee that also requires stack fixups can happen when
// there are no available registers at the candidate callsite for a
// candidate that itself also has calls.
//
// In other words if function_containing_sequence in the following pseudo
// assembly requires that we save LR at the point of the call, but there
// are no available registers: in this case we save using SP and as a
// result the SP offsets requires stack fixups by multiples of 16.
//
// function_containing_sequence:
// ...
// save LR to SP <- Requires stack instr fixups in OUTLINED_FUNCTION_N
// call OUTLINED_FUNCTION_N
// restore LR from SP
// ...
//
// OUTLINED_FUNCTION_N:
// save LR to SP <- Requires stack instr fixups in OUTLINED_FUNCTION_N
// ...
// bl foo
// restore LR from SP
// ret
//
// Because the code to handle more than one stack fixup does not
// currently have the proper checks for legality, these cases will assert
// in the AArch64 MachineOutliner. This is because the code to do this
// needs more hardening, testing, better checks that generated code is
// legal, etc and because it is only verified to handle a single pass of
// stack fixup.
//
// The assert happens in AArch64InstrInfo::buildOutlinedFrame to catch
// these cases until they are known to be handled. Bugzilla 46767 is
// referenced in comments at the assert site.
//
// To avoid asserting (or generating non-legal code on noassert builds)
// we remove all candidates which would need more than one stack fixup by
// pruning the cases where the candidate has calls while also having no
// available LR and having no available general purpose registers to copy
// LR to (ie one extra stack save/restore).
//
if (FlagsSetInAll & MachineOutlinerMBBFlags::HasCalls) {
erase_if(RepeatedSequenceLocs, [this](outliner::Candidate &C) {
return (std::any_of(
C.front(), std::next(C.back()),
[](const MachineInstr &MI) { return MI.isCall(); })) &&
(!C.LRU.available(AArch64::LR) || !findRegisterToSaveLRTo(C));
});
}
}

// If we dropped all of the candidates, bail out here.
Expand Down Expand Up @@ -6616,6 +6670,9 @@ void AArch64InstrInfo::buildOutlinedFrame(
if (std::any_of(MBB.instr_begin(), MBB.instr_end(), IsNonTailCall)) {
// Fix up the instructions in the range, since we're going to modify the
// stack.

// Bugzilla ID: 46767
// TODO: Check if fixing up twice is safe so we can outline these.
assert(OF.FrameConstructionID != MachineOutlinerDefault &&
"Can only fix up stack references once");
fixupPostOutline(MBB);
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Transforms/IPO/SampleProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,8 @@ SampleProfileLoader::findCalleeFunctionSamples(const CallBase &Inst) const {
}

StringRef CalleeName;
if (const CallInst *CI = dyn_cast<CallInst>(&Inst))
if (Function *Callee = CI->getCalledFunction())
CalleeName = Callee->getName();
if (Function *Callee = Inst.getCalledFunction())
CalleeName = Callee->getName();

const FunctionSamples *FS = findFunctionSamples(Inst);
if (FS == nullptr)
Expand Down
Loading

0 comments on commit b2a0e72

Please sign in to comment.