2017-02-17 00:00:09 +00:00
|
|
|
//===- InlineAsm.cpp - Implement the InlineAsm class ----------------------===//
|
2006-01-24 04:13:11 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2006-01-24 04:13:11 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the InlineAsm class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 11:49:48 +00:00
|
|
|
#include "llvm/IR/InlineAsm.h"
|
2010-03-21 20:37:19 +00:00
|
|
|
#include "ConstantsContext.h"
|
|
|
|
#include "LLVMContextImpl.h"
|
2017-02-17 00:00:09 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
2017-02-17 00:00:09 +00:00
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Value.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
2022-07-12 11:20:49 +02:00
|
|
|
#include "llvm/Support/Errc.h"
|
2006-02-01 04:37:04 +00:00
|
|
|
#include <algorithm>
|
2017-02-17 00:00:09 +00:00
|
|
|
#include <cassert>
|
2006-01-26 00:48:33 +00:00
|
|
|
#include <cctype>
|
2017-02-17 00:00:09 +00:00
|
|
|
#include <cstdlib>
|
2007-12-10 02:14:30 +00:00
|
|
|
|
2017-02-17 00:00:09 +00:00
|
|
|
using namespace llvm;
|
2006-01-25 22:26:05 +00:00
|
|
|
|
2015-07-28 00:06:38 +00:00
|
|
|
InlineAsm::InlineAsm(FunctionType *FTy, const std::string &asmString,
|
2010-03-21 20:37:19 +00:00
|
|
|
const std::string &constraints, bool hasSideEffects,
|
2021-05-13 19:05:11 +01:00
|
|
|
bool isAlignStack, AsmDialect asmDialect, bool canThrow)
|
2025-01-23 18:23:05 +09:00
|
|
|
: Value(PointerType::getUnqual(FTy->getContext()), Value::InlineAsmVal),
|
2015-07-28 00:06:38 +00:00
|
|
|
AsmString(asmString), Constraints(constraints), FTy(FTy),
|
|
|
|
HasSideEffects(hasSideEffects), IsAlignStack(isAlignStack),
|
2021-05-13 19:05:11 +01:00
|
|
|
Dialect(asmDialect), CanThrow(canThrow) {
|
2022-07-12 11:20:49 +02:00
|
|
|
#ifndef NDEBUG
|
2006-01-25 22:26:05 +00:00
|
|
|
// Do various checks on the constraint string and type.
|
2022-07-12 11:20:49 +02:00
|
|
|
cantFail(verify(getFunctionType(), constraints));
|
|
|
|
#endif
|
2010-03-21 20:37:19 +00:00
|
|
|
}
|
|
|
|
|
2017-02-17 00:00:09 +00:00
|
|
|
InlineAsm *InlineAsm::get(FunctionType *FTy, StringRef AsmString,
|
|
|
|
StringRef Constraints, bool hasSideEffects,
|
2021-05-13 19:05:11 +01:00
|
|
|
bool isAlignStack, AsmDialect asmDialect,
|
|
|
|
bool canThrow) {
|
2017-02-17 00:00:09 +00:00
|
|
|
InlineAsmKeyType Key(AsmString, Constraints, FTy, hasSideEffects,
|
2021-05-13 19:05:11 +01:00
|
|
|
isAlignStack, asmDialect, canThrow);
|
2017-02-17 00:00:09 +00:00
|
|
|
LLVMContextImpl *pImpl = FTy->getContext().pImpl;
|
2025-01-23 18:23:05 +09:00
|
|
|
return pImpl->InlineAsms.getOrCreate(
|
|
|
|
PointerType::getUnqual(FTy->getContext()), Key);
|
2017-02-17 00:00:09 +00:00
|
|
|
}
|
|
|
|
|
2010-03-21 20:37:19 +00:00
|
|
|
void InlineAsm::destroyConstant() {
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
llvm-svn: 134829
2011-07-09 17:41:24 +00:00
|
|
|
getType()->getContext().pImpl->InlineAsms.remove(this);
|
2010-03-21 20:37:19 +00:00
|
|
|
delete this;
|
2006-01-24 04:13:11 +00:00
|
|
|
}
|
|
|
|
|
2011-07-15 23:15:45 +00:00
|
|
|
FunctionType *InlineAsm::getFunctionType() const {
|
2015-07-28 00:06:38 +00:00
|
|
|
return FTy;
|
2006-01-24 04:13:11 +00:00
|
|
|
}
|
2018-07-30 19:41:25 +00:00
|
|
|
|
2022-09-13 14:48:12 +08:00
|
|
|
void InlineAsm::collectAsmStrs(SmallVectorImpl<StringRef> &AsmStrs) const {
|
|
|
|
StringRef AsmStr(AsmString);
|
|
|
|
AsmStrs.clear();
|
|
|
|
|
|
|
|
// TODO: 1) Unify delimiter for inline asm, we also meet other delimiters
|
|
|
|
// for example "\0A", ";".
|
|
|
|
// 2) Enhance StringRef. Some of the special delimiter ("\0") can't be
|
|
|
|
// split in StringRef. Also empty StringRef can not call split (will stuck).
|
|
|
|
if (AsmStr.empty())
|
|
|
|
return;
|
|
|
|
AsmStr.split(AsmStrs, "\n\t", -1, false);
|
|
|
|
}
|
|
|
|
|
2006-02-01 01:29:47 +00:00
|
|
|
/// Parse - Analyze the specified string (e.g. "==&{eax}") and fill in the
|
|
|
|
/// fields in this structure. If the constraint string is not understood,
|
|
|
|
/// return true, otherwise return false.
|
2009-11-06 10:58:06 +00:00
|
|
|
bool InlineAsm::ConstraintInfo::Parse(StringRef Str,
|
2010-10-29 17:29:13 +00:00
|
|
|
InlineAsm::ConstraintInfoVector &ConstraintsSoFar) {
|
2009-07-25 06:02:13 +00:00
|
|
|
StringRef::iterator I = Str.begin(), E = Str.end();
|
2010-09-13 18:15:37 +00:00
|
|
|
unsigned multipleAlternativeCount = Str.count('|') + 1;
|
|
|
|
unsigned multipleAlternativeIndex = 0;
|
2010-10-29 17:29:13 +00:00
|
|
|
ConstraintCodeVector *pCodes = &Codes;
|
2015-02-10 21:15:06 +00:00
|
|
|
|
2006-02-01 01:29:47 +00:00
|
|
|
// Initialize
|
2015-03-09 01:57:13 +00:00
|
|
|
isMultipleAlternative = multipleAlternativeCount > 1;
|
2010-09-13 18:15:37 +00:00
|
|
|
if (isMultipleAlternative) {
|
|
|
|
multipleAlternatives.resize(multipleAlternativeCount);
|
|
|
|
pCodes = &multipleAlternatives[0].Codes;
|
|
|
|
}
|
2006-02-01 01:29:47 +00:00
|
|
|
Type = isInput;
|
|
|
|
isEarlyClobber = false;
|
2008-10-17 16:47:46 +00:00
|
|
|
MatchingInput = -1;
|
2006-02-23 23:36:53 +00:00
|
|
|
isCommutative = false;
|
2007-04-28 01:02:58 +00:00
|
|
|
isIndirect = false;
|
2010-09-13 18:15:37 +00:00
|
|
|
currentAlternativeIndex = 0;
|
2018-07-30 19:41:25 +00:00
|
|
|
|
2007-04-28 01:02:58 +00:00
|
|
|
// Parse prefixes.
|
2006-02-01 01:29:47 +00:00
|
|
|
if (*I == '~') {
|
|
|
|
Type = isClobber;
|
|
|
|
++I;
|
2014-09-05 22:30:32 +00:00
|
|
|
|
|
|
|
// '{' must immediately follow '~'.
|
|
|
|
if (I != E && *I != '{')
|
|
|
|
return true;
|
2006-02-01 01:29:47 +00:00
|
|
|
} else if (*I == '=') {
|
|
|
|
++I;
|
|
|
|
Type = isOutput;
|
[IR] Don't use blockaddresses as callbr arguments
Following some recent discussions, this changes the representation
of callbrs in IR. The current blockaddress arguments are replaced
with `!` label constraints that refer directly to callbr indirect
destinations:
; Before:
%res = callbr i8* asm "", "=r,r,i"(i8* %x, i8* blockaddress(@test8, %foo))
to label %asm.fallthrough [label %foo]
; After:
%res = callbr i8* asm "", "=r,r,!i"(i8* %x)
to label %asm.fallthrough [label %foo]
The benefit of this is that we can easily update the successors of
a callbr, without having to worry about also updating blockaddress
references. This should allow us to remove some limitations:
* Allow unrolling/peeling/rotation of callbr, or any other
clone-based optimizations
(https://github.com/llvm/llvm-project/issues/41834)
* Allow duplicate successors
(https://github.com/llvm/llvm-project/issues/45248)
This is just the IR representation change though, I will follow up
with patches to remove limtations in various transformation passes
that are no longer needed.
Differential Revision: https://reviews.llvm.org/D129288
2022-07-07 12:27:43 +02:00
|
|
|
} else if (*I == '!') {
|
|
|
|
++I;
|
|
|
|
Type = isLabel;
|
2007-04-28 01:02:58 +00:00
|
|
|
}
|
2015-02-10 21:15:06 +00:00
|
|
|
|
2007-04-28 01:02:58 +00:00
|
|
|
if (*I == '*') {
|
|
|
|
isIndirect = true;
|
|
|
|
++I;
|
2006-02-01 01:29:47 +00:00
|
|
|
}
|
2015-02-10 21:15:06 +00:00
|
|
|
|
2006-02-01 01:29:47 +00:00
|
|
|
if (I == E) return true; // Just a prefix, like "==" or "~".
|
2018-07-30 19:41:25 +00:00
|
|
|
|
2006-02-01 01:29:47 +00:00
|
|
|
// Parse the modifiers.
|
|
|
|
bool DoneWithModifiers = false;
|
|
|
|
while (!DoneWithModifiers) {
|
|
|
|
switch (*I) {
|
|
|
|
default:
|
|
|
|
DoneWithModifiers = true;
|
|
|
|
break;
|
2006-02-23 23:36:53 +00:00
|
|
|
case '&': // Early clobber.
|
2006-02-01 01:29:47 +00:00
|
|
|
if (Type != isOutput || // Cannot early clobber anything but output.
|
|
|
|
isEarlyClobber) // Reject &&&&&&
|
|
|
|
return true;
|
|
|
|
isEarlyClobber = true;
|
|
|
|
break;
|
2006-02-23 23:36:53 +00:00
|
|
|
case '%': // Commutative.
|
|
|
|
if (Type == isClobber || // Cannot commute clobbers.
|
|
|
|
isCommutative) // Reject %%%%%
|
|
|
|
return true;
|
|
|
|
isCommutative = true;
|
|
|
|
break;
|
|
|
|
case '#': // Comment.
|
|
|
|
case '*': // Register preferencing.
|
|
|
|
return true; // Not supported.
|
2006-02-01 01:29:47 +00:00
|
|
|
}
|
2018-07-30 19:41:25 +00:00
|
|
|
|
2006-02-01 01:29:47 +00:00
|
|
|
if (!DoneWithModifiers) {
|
2006-01-26 00:48:33 +00:00
|
|
|
++I;
|
2006-02-01 01:29:47 +00:00
|
|
|
if (I == E) return true; // Just prefixes and modifiers!
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 19:41:25 +00:00
|
|
|
|
2006-02-01 01:29:47 +00:00
|
|
|
// Parse the various constraints.
|
|
|
|
while (I != E) {
|
|
|
|
if (*I == '{') { // Physical register reference.
|
|
|
|
// Find the end of the register name.
|
2009-07-25 06:02:13 +00:00
|
|
|
StringRef::iterator ConstraintEnd = std::find(I+1, E, '}');
|
2006-02-01 01:29:47 +00:00
|
|
|
if (ConstraintEnd == E) return true; // "{foo"
|
2020-01-28 20:23:46 +01:00
|
|
|
pCodes->push_back(std::string(StringRef(I, ConstraintEnd + 1 - I)));
|
2006-02-01 01:29:47 +00:00
|
|
|
I = ConstraintEnd+1;
|
2013-02-12 21:21:59 +00:00
|
|
|
} else if (isdigit(static_cast<unsigned char>(*I))) { // Matching Constraint
|
2006-02-01 01:29:47 +00:00
|
|
|
// Maximal munch numbers.
|
2009-07-25 06:02:13 +00:00
|
|
|
StringRef::iterator NumStart = I;
|
2013-02-12 21:21:59 +00:00
|
|
|
while (I != E && isdigit(static_cast<unsigned char>(*I)))
|
2006-01-26 00:48:33 +00:00
|
|
|
++I;
|
2020-01-28 20:23:46 +01:00
|
|
|
pCodes->push_back(std::string(StringRef(NumStart, I - NumStart)));
|
2010-09-13 18:15:37 +00:00
|
|
|
unsigned N = atoi(pCodes->back().c_str());
|
2006-02-02 00:23:53 +00:00
|
|
|
// Check that this is a valid matching constraint!
|
|
|
|
if (N >= ConstraintsSoFar.size() || ConstraintsSoFar[N].Type != isOutput||
|
|
|
|
Type != isInput)
|
|
|
|
return true; // Invalid constraint number.
|
2018-07-30 19:41:25 +00:00
|
|
|
|
2008-10-17 16:47:46 +00:00
|
|
|
// If Operand N already has a matching input, reject this. An output
|
|
|
|
// can't be constrained to the same value as multiple inputs.
|
2010-09-13 18:15:37 +00:00
|
|
|
if (isMultipleAlternative) {
|
2015-09-03 15:41:37 +00:00
|
|
|
if (multipleAlternativeIndex >=
|
|
|
|
ConstraintsSoFar[N].multipleAlternatives.size())
|
2015-09-03 15:41:34 +00:00
|
|
|
return true;
|
2010-09-13 18:15:37 +00:00
|
|
|
InlineAsm::SubConstraintInfo &scInfo =
|
|
|
|
ConstraintsSoFar[N].multipleAlternatives[multipleAlternativeIndex];
|
|
|
|
if (scInfo.MatchingInput != -1)
|
|
|
|
return true;
|
|
|
|
// Note that operand #n has a matching input.
|
|
|
|
scInfo.MatchingInput = ConstraintsSoFar.size();
|
2017-10-25 12:51:32 +00:00
|
|
|
assert(scInfo.MatchingInput >= 0);
|
2010-09-13 18:15:37 +00:00
|
|
|
} else {
|
2015-03-29 20:33:07 +00:00
|
|
|
if (ConstraintsSoFar[N].hasMatchingInput() &&
|
2015-03-29 20:49:03 +00:00
|
|
|
(size_t)ConstraintsSoFar[N].MatchingInput !=
|
|
|
|
ConstraintsSoFar.size())
|
2010-09-13 18:15:37 +00:00
|
|
|
return true;
|
|
|
|
// Note that operand #n has a matching input.
|
|
|
|
ConstraintsSoFar[N].MatchingInput = ConstraintsSoFar.size();
|
2017-10-25 12:51:32 +00:00
|
|
|
assert(ConstraintsSoFar[N].MatchingInput >= 0);
|
2010-09-13 18:15:37 +00:00
|
|
|
}
|
|
|
|
} else if (*I == '|') {
|
|
|
|
multipleAlternativeIndex++;
|
|
|
|
pCodes = &multipleAlternatives[multipleAlternativeIndex].Codes;
|
|
|
|
++I;
|
2011-06-02 19:26:37 +00:00
|
|
|
} else if (*I == '^') {
|
|
|
|
// Multi-letter constraint
|
2011-06-03 22:09:12 +00:00
|
|
|
// FIXME: For now assuming these are 2-character constraints.
|
2020-01-28 20:23:46 +01:00
|
|
|
pCodes->push_back(std::string(StringRef(I + 1, 2)));
|
2011-06-03 22:09:12 +00:00
|
|
|
I += 3;
|
[SVE][Inline-Asm] Add constraints for SVE predicate registers
Summary:
Adds the following inline asm constraints for SVE:
- Upl: One of the low eight SVE predicate registers, P0 to P7 inclusive
- Upa: SVE predicate register with full range, P0 to P15
Reviewers: t.p.northover, sdesmalen, rovka, momchil.velikov, cameron.mcinally, greened, rengolin
Reviewed By: rovka
Subscribers: javed.absar, tschuett, rkruppe, psnobl, cfe-commits, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66524
llvm-svn: 371967
2019-09-16 09:45:27 +00:00
|
|
|
} else if (*I == '@') {
|
|
|
|
// Multi-letter constraint
|
|
|
|
++I;
|
|
|
|
unsigned char C = static_cast<unsigned char>(*I);
|
|
|
|
assert(isdigit(C) && "Expected a digit!");
|
|
|
|
int N = C - '0';
|
|
|
|
assert(N > 0 && "Found a zero letter constraint!");
|
|
|
|
++I;
|
2020-01-28 20:23:46 +01:00
|
|
|
pCodes->push_back(std::string(StringRef(I, N)));
|
[SVE][Inline-Asm] Add constraints for SVE predicate registers
Summary:
Adds the following inline asm constraints for SVE:
- Upl: One of the low eight SVE predicate registers, P0 to P7 inclusive
- Upa: SVE predicate register with full range, P0 to P15
Reviewers: t.p.northover, sdesmalen, rovka, momchil.velikov, cameron.mcinally, greened, rengolin
Reviewed By: rovka
Subscribers: javed.absar, tschuett, rkruppe, psnobl, cfe-commits, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66524
llvm-svn: 371967
2019-09-16 09:45:27 +00:00
|
|
|
I += N;
|
2006-02-01 01:29:47 +00:00
|
|
|
} else {
|
|
|
|
// Single letter constraint.
|
2020-01-28 20:23:46 +01:00
|
|
|
pCodes->push_back(std::string(StringRef(I, 1)));
|
2006-02-01 01:29:47 +00:00
|
|
|
++I;
|
2006-01-26 00:48:33 +00:00
|
|
|
}
|
2006-02-01 01:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-13 18:15:37 +00:00
|
|
|
/// selectAlternative - Point this constraint to the alternative constraint
|
|
|
|
/// indicated by the index.
|
|
|
|
void InlineAsm::ConstraintInfo::selectAlternative(unsigned index) {
|
|
|
|
if (index < multipleAlternatives.size()) {
|
|
|
|
currentAlternativeIndex = index;
|
|
|
|
InlineAsm::SubConstraintInfo &scInfo =
|
|
|
|
multipleAlternatives[currentAlternativeIndex];
|
|
|
|
MatchingInput = scInfo.MatchingInput;
|
|
|
|
Codes = scInfo.Codes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-29 17:29:13 +00:00
|
|
|
InlineAsm::ConstraintInfoVector
|
2009-11-06 10:58:06 +00:00
|
|
|
InlineAsm::ParseConstraints(StringRef Constraints) {
|
2010-10-29 17:29:13 +00:00
|
|
|
ConstraintInfoVector Result;
|
2018-07-30 19:41:25 +00:00
|
|
|
|
2006-02-01 01:29:47 +00:00
|
|
|
// Scan the constraints string.
|
2009-07-25 06:02:13 +00:00
|
|
|
for (StringRef::iterator I = Constraints.begin(),
|
|
|
|
E = Constraints.end(); I != E; ) {
|
2006-02-01 01:29:47 +00:00
|
|
|
ConstraintInfo Info;
|
|
|
|
|
|
|
|
// Find the end of this constraint.
|
2009-07-25 06:02:13 +00:00
|
|
|
StringRef::iterator ConstraintEnd = std::find(I, E, ',');
|
2006-02-01 01:29:47 +00:00
|
|
|
|
|
|
|
if (ConstraintEnd == I || // Empty constraint like ",,"
|
2010-07-25 23:18:32 +00:00
|
|
|
Info.Parse(StringRef(I, ConstraintEnd-I), Result)) {
|
2006-02-02 00:23:53 +00:00
|
|
|
Result.clear(); // Erroneous constraint?
|
2006-01-26 02:21:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-02-01 01:29:47 +00:00
|
|
|
|
|
|
|
Result.push_back(Info);
|
2018-07-30 19:41:25 +00:00
|
|
|
|
2006-02-01 01:29:47 +00:00
|
|
|
// ConstraintEnd may be either the next comma or the end of the string. In
|
|
|
|
// the former case, we skip the comma.
|
|
|
|
I = ConstraintEnd;
|
2006-01-26 02:21:59 +00:00
|
|
|
if (I != E) {
|
|
|
|
++I;
|
2015-02-10 21:15:06 +00:00
|
|
|
if (I == E) {
|
|
|
|
Result.clear();
|
|
|
|
break;
|
|
|
|
} // don't allow "xyz,"
|
2006-01-26 02:21:59 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-30 19:41:25 +00:00
|
|
|
|
2006-01-26 02:21:59 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2022-07-12 11:20:49 +02:00
|
|
|
static Error makeStringError(const char *Msg) {
|
|
|
|
return createStringError(errc::invalid_argument, Msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
Error InlineAsm::verify(FunctionType *Ty, StringRef ConstStr) {
|
|
|
|
if (Ty->isVarArg())
|
|
|
|
return makeStringError("inline asm cannot be variadic");
|
2018-07-30 19:41:25 +00:00
|
|
|
|
2010-10-29 17:29:13 +00:00
|
|
|
ConstraintInfoVector Constraints = ParseConstraints(ConstStr);
|
2018-07-30 19:41:25 +00:00
|
|
|
|
2006-01-26 02:21:59 +00:00
|
|
|
// Error parsing constraints.
|
2022-07-12 11:20:49 +02:00
|
|
|
if (Constraints.empty() && !ConstStr.empty())
|
|
|
|
return makeStringError("failed to parse constraints");
|
2018-07-30 19:41:25 +00:00
|
|
|
|
2006-01-26 02:21:59 +00:00
|
|
|
unsigned NumOutputs = 0, NumInputs = 0, NumClobbers = 0;
|
[IR] Don't use blockaddresses as callbr arguments
Following some recent discussions, this changes the representation
of callbrs in IR. The current blockaddress arguments are replaced
with `!` label constraints that refer directly to callbr indirect
destinations:
; Before:
%res = callbr i8* asm "", "=r,r,i"(i8* %x, i8* blockaddress(@test8, %foo))
to label %asm.fallthrough [label %foo]
; After:
%res = callbr i8* asm "", "=r,r,!i"(i8* %x)
to label %asm.fallthrough [label %foo]
The benefit of this is that we can easily update the successors of
a callbr, without having to worry about also updating blockaddress
references. This should allow us to remove some limitations:
* Allow unrolling/peeling/rotation of callbr, or any other
clone-based optimizations
(https://github.com/llvm/llvm-project/issues/41834)
* Allow duplicate successors
(https://github.com/llvm/llvm-project/issues/45248)
This is just the IR representation change though, I will follow up
with patches to remove limtations in various transformation passes
that are no longer needed.
Differential Revision: https://reviews.llvm.org/D129288
2022-07-07 12:27:43 +02:00
|
|
|
unsigned NumIndirect = 0, NumLabels = 0;
|
2018-07-30 19:41:25 +00:00
|
|
|
|
2021-12-09 09:37:29 -08:00
|
|
|
for (const ConstraintInfo &Constraint : Constraints) {
|
|
|
|
switch (Constraint.Type) {
|
2006-02-01 01:29:47 +00:00
|
|
|
case InlineAsm::isOutput:
|
[IR] Don't use blockaddresses as callbr arguments
Following some recent discussions, this changes the representation
of callbrs in IR. The current blockaddress arguments are replaced
with `!` label constraints that refer directly to callbr indirect
destinations:
; Before:
%res = callbr i8* asm "", "=r,r,i"(i8* %x, i8* blockaddress(@test8, %foo))
to label %asm.fallthrough [label %foo]
; After:
%res = callbr i8* asm "", "=r,r,!i"(i8* %x)
to label %asm.fallthrough [label %foo]
The benefit of this is that we can easily update the successors of
a callbr, without having to worry about also updating blockaddress
references. This should allow us to remove some limitations:
* Allow unrolling/peeling/rotation of callbr, or any other
clone-based optimizations
(https://github.com/llvm/llvm-project/issues/41834)
* Allow duplicate successors
(https://github.com/llvm/llvm-project/issues/45248)
This is just the IR representation change though, I will follow up
with patches to remove limtations in various transformation passes
that are no longer needed.
Differential Revision: https://reviews.llvm.org/D129288
2022-07-07 12:27:43 +02:00
|
|
|
if ((NumInputs-NumIndirect) != 0 || NumClobbers != 0 || NumLabels != 0)
|
|
|
|
return makeStringError("output constraint occurs after input, "
|
|
|
|
"clobber or label constraint");
|
2022-07-12 11:20:49 +02:00
|
|
|
|
2021-12-09 09:37:29 -08:00
|
|
|
if (!Constraint.isIndirect) {
|
2006-02-01 01:29:47 +00:00
|
|
|
++NumOutputs;
|
|
|
|
break;
|
|
|
|
}
|
2008-05-22 04:46:38 +00:00
|
|
|
++NumIndirect;
|
2022-08-08 11:24:15 -07:00
|
|
|
[[fallthrough]]; // We fall through for Indirect Outputs.
|
2006-02-01 01:29:47 +00:00
|
|
|
case InlineAsm::isInput:
|
2022-07-12 11:20:49 +02:00
|
|
|
if (NumClobbers)
|
|
|
|
return makeStringError("input constraint occurs after clobber "
|
|
|
|
"constraint");
|
2006-01-26 00:48:33 +00:00
|
|
|
++NumInputs;
|
|
|
|
break;
|
2006-02-01 01:29:47 +00:00
|
|
|
case InlineAsm::isClobber:
|
2006-01-26 00:48:33 +00:00
|
|
|
++NumClobbers;
|
|
|
|
break;
|
[IR] Don't use blockaddresses as callbr arguments
Following some recent discussions, this changes the representation
of callbrs in IR. The current blockaddress arguments are replaced
with `!` label constraints that refer directly to callbr indirect
destinations:
; Before:
%res = callbr i8* asm "", "=r,r,i"(i8* %x, i8* blockaddress(@test8, %foo))
to label %asm.fallthrough [label %foo]
; After:
%res = callbr i8* asm "", "=r,r,!i"(i8* %x)
to label %asm.fallthrough [label %foo]
The benefit of this is that we can easily update the successors of
a callbr, without having to worry about also updating blockaddress
references. This should allow us to remove some limitations:
* Allow unrolling/peeling/rotation of callbr, or any other
clone-based optimizations
(https://github.com/llvm/llvm-project/issues/41834)
* Allow duplicate successors
(https://github.com/llvm/llvm-project/issues/45248)
This is just the IR representation change though, I will follow up
with patches to remove limtations in various transformation passes
that are no longer needed.
Differential Revision: https://reviews.llvm.org/D129288
2022-07-07 12:27:43 +02:00
|
|
|
case InlineAsm::isLabel:
|
|
|
|
if (NumClobbers)
|
|
|
|
return makeStringError("label constraint occurs after clobber "
|
|
|
|
"constraint");
|
|
|
|
|
|
|
|
++NumLabels;
|
|
|
|
break;
|
2006-01-26 00:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-30 19:41:25 +00:00
|
|
|
|
2008-04-27 23:33:55 +00:00
|
|
|
switch (NumOutputs) {
|
|
|
|
case 0:
|
2022-07-12 11:20:49 +02:00
|
|
|
if (!Ty->getReturnType()->isVoidTy())
|
|
|
|
return makeStringError("inline asm without outputs must return void");
|
2008-04-27 23:33:55 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2022-07-12 11:20:49 +02:00
|
|
|
if (Ty->getReturnType()->isStructTy())
|
|
|
|
return makeStringError("inline asm with one output cannot return struct");
|
2008-04-27 23:33:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
2011-07-18 04:54:35 +00:00
|
|
|
StructType *STy = dyn_cast<StructType>(Ty->getReturnType());
|
2014-04-09 06:08:46 +00:00
|
|
|
if (!STy || STy->getNumElements() != NumOutputs)
|
2022-07-12 11:20:49 +02:00
|
|
|
return makeStringError("number of output constraints does not match "
|
|
|
|
"number of return struct elements");
|
2008-04-27 23:33:55 +00:00
|
|
|
break;
|
2018-07-30 19:41:25 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 11:20:49 +02:00
|
|
|
if (Ty->getNumParams() != NumInputs)
|
|
|
|
return makeStringError("number of input constraints does not match number "
|
|
|
|
"of parameters");
|
[IR] Don't use blockaddresses as callbr arguments
Following some recent discussions, this changes the representation
of callbrs in IR. The current blockaddress arguments are replaced
with `!` label constraints that refer directly to callbr indirect
destinations:
; Before:
%res = callbr i8* asm "", "=r,r,i"(i8* %x, i8* blockaddress(@test8, %foo))
to label %asm.fallthrough [label %foo]
; After:
%res = callbr i8* asm "", "=r,r,!i"(i8* %x)
to label %asm.fallthrough [label %foo]
The benefit of this is that we can easily update the successors of
a callbr, without having to worry about also updating blockaddress
references. This should allow us to remove some limitations:
* Allow unrolling/peeling/rotation of callbr, or any other
clone-based optimizations
(https://github.com/llvm/llvm-project/issues/41834)
* Allow duplicate successors
(https://github.com/llvm/llvm-project/issues/45248)
This is just the IR representation change though, I will follow up
with patches to remove limtations in various transformation passes
that are no longer needed.
Differential Revision: https://reviews.llvm.org/D129288
2022-07-07 12:27:43 +02:00
|
|
|
|
|
|
|
// We don't have access to labels here, NumLabels will be checked separately.
|
2022-07-12 11:20:49 +02:00
|
|
|
return Error::success();
|
2006-01-25 22:26:05 +00:00
|
|
|
}
|