2017-09-28 07:26:01 +08:00
|
|
|
//===- MILexer.h - Lexer for machine instructions ---------------*- C++ -*-===//
|
2015-06-23 04:37:46 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the function that lexes the machine instruction source
|
|
|
|
// string.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
|
|
|
|
#define LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
|
|
|
|
|
2015-06-24 07:42:28 +08:00
|
|
|
#include "llvm/ADT/APSInt.h"
|
2015-06-23 04:37:46 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2017-09-28 07:26:01 +08:00
|
|
|
#include <string>
|
2015-06-23 04:37:46 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class Twine;
|
|
|
|
|
|
|
|
/// A token produced by the machine instruction lexer.
|
|
|
|
struct MIToken {
|
|
|
|
enum TokenKind {
|
|
|
|
// Markers
|
|
|
|
Eof,
|
|
|
|
Error,
|
2015-08-14 07:10:16 +08:00
|
|
|
Newline,
|
2015-06-23 04:37:46 +08:00
|
|
|
|
2015-06-24 00:35:26 +08:00
|
|
|
// Tokens with no info.
|
|
|
|
comma,
|
|
|
|
equal,
|
2015-06-25 01:34:58 +08:00
|
|
|
underscore,
|
2015-07-14 07:24:34 +08:00
|
|
|
colon,
|
2015-08-04 07:08:19 +08:00
|
|
|
coloncolon,
|
2016-07-27 05:49:34 +08:00
|
|
|
dot,
|
2015-07-23 01:58:46 +08:00
|
|
|
exclaim,
|
2015-07-29 01:28:03 +08:00
|
|
|
lparen,
|
|
|
|
rparen,
|
2015-08-15 02:57:24 +08:00
|
|
|
lbrace,
|
|
|
|
rbrace,
|
2015-08-06 06:26:15 +08:00
|
|
|
plus,
|
|
|
|
minus,
|
2016-03-08 10:00:43 +08:00
|
|
|
less,
|
|
|
|
greater,
|
2015-06-24 00:35:26 +08:00
|
|
|
|
2015-07-07 07:07:26 +08:00
|
|
|
// Keywords
|
|
|
|
kw_implicit,
|
|
|
|
kw_implicit_define,
|
2015-08-20 02:55:47 +08:00
|
|
|
kw_def,
|
2015-07-08 04:34:53 +08:00
|
|
|
kw_dead,
|
[CodeGen] Split out the notions of MI invariance and MI dereferenceability.
Summary:
An IR load can be invariant, dereferenceable, neither, or both. But
currently, MI's notion of invariance is IR-invariant &&
IR-dereferenceable.
This patch splits up the notions of invariance and dereferenceability at
the MI level. It's NFC, so adds some probably-unnecessary
"is-dereferenceable" checks, which we can remove later if desired.
Reviewers: chandlerc, tstellarAMD
Subscribers: jholewinski, arsenm, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D23371
llvm-svn: 281151
2016-09-11 09:38:58 +08:00
|
|
|
kw_dereferenceable,
|
2015-07-09 05:23:34 +08:00
|
|
|
kw_killed,
|
2015-07-09 07:58:31 +08:00
|
|
|
kw_undef,
|
2015-08-15 03:07:07 +08:00
|
|
|
kw_internal,
|
2015-08-06 01:49:03 +08:00
|
|
|
kw_early_clobber,
|
2015-08-06 01:41:17 +08:00
|
|
|
kw_debug_use,
|
2015-08-20 03:05:34 +08:00
|
|
|
kw_tied_def,
|
2015-07-17 08:24:15 +08:00
|
|
|
kw_frame_setup,
|
2015-07-23 05:15:11 +08:00
|
|
|
kw_debug_location,
|
2015-08-15 05:55:58 +08:00
|
|
|
kw_cfi_same_value,
|
2015-07-24 07:09:07 +08:00
|
|
|
kw_cfi_offset,
|
2015-07-28 04:39:03 +08:00
|
|
|
kw_cfi_def_cfa_register,
|
2015-07-22 06:28:27 +08:00
|
|
|
kw_cfi_def_cfa_offset,
|
2015-07-30 02:57:23 +08:00
|
|
|
kw_cfi_def_cfa,
|
2015-07-29 01:28:03 +08:00
|
|
|
kw_blockaddress,
|
2016-07-30 04:32:59 +08:00
|
|
|
kw_intrinsic,
|
2015-07-29 07:02:45 +08:00
|
|
|
kw_target_index,
|
2015-08-01 04:49:21 +08:00
|
|
|
kw_half,
|
|
|
|
kw_float,
|
|
|
|
kw_double,
|
|
|
|
kw_x86_fp80,
|
|
|
|
kw_fp128,
|
|
|
|
kw_ppc_fp128,
|
2015-08-06 08:44:07 +08:00
|
|
|
kw_target_flags,
|
2015-08-04 08:24:45 +08:00
|
|
|
kw_volatile,
|
2015-08-07 00:49:30 +08:00
|
|
|
kw_non_temporal,
|
2015-08-07 00:55:53 +08:00
|
|
|
kw_invariant,
|
2015-08-08 04:48:30 +08:00
|
|
|
kw_align,
|
2015-08-13 04:44:16 +08:00
|
|
|
kw_stack,
|
2015-08-13 05:00:22 +08:00
|
|
|
kw_got,
|
2015-08-13 05:11:08 +08:00
|
|
|
kw_jump_table,
|
2015-08-13 04:33:26 +08:00
|
|
|
kw_constant_pool,
|
2015-08-20 08:12:57 +08:00
|
|
|
kw_call_entry,
|
2015-08-11 07:24:42 +08:00
|
|
|
kw_liveout,
|
2015-08-14 07:10:16 +08:00
|
|
|
kw_address_taken,
|
|
|
|
kw_landing_pad,
|
|
|
|
kw_liveins,
|
|
|
|
kw_successors,
|
2016-08-18 04:25:25 +08:00
|
|
|
kw_floatpred,
|
|
|
|
kw_intpred,
|
2015-07-07 07:07:26 +08:00
|
|
|
|
2015-08-18 06:05:15 +08:00
|
|
|
// Named metadata keywords
|
|
|
|
md_tbaa,
|
2015-08-18 06:06:40 +08:00
|
|
|
md_alias_scope,
|
2015-08-18 06:08:02 +08:00
|
|
|
md_noalias,
|
2015-08-18 06:09:52 +08:00
|
|
|
md_range,
|
2017-08-24 04:31:27 +08:00
|
|
|
md_diexpr,
|
2015-08-18 06:05:15 +08:00
|
|
|
|
2015-06-23 04:37:46 +08:00
|
|
|
// Identifier tokens
|
2015-06-24 00:35:26 +08:00
|
|
|
Identifier,
|
2015-08-06 02:52:21 +08:00
|
|
|
IntegerType,
|
2015-06-24 07:42:28 +08:00
|
|
|
NamedRegister,
|
2015-08-14 07:10:16 +08:00
|
|
|
MachineBasicBlockLabel,
|
2015-06-27 00:46:11 +08:00
|
|
|
MachineBasicBlock,
|
2016-07-23 00:59:52 +08:00
|
|
|
PointerType,
|
2016-07-21 03:09:30 +08:00
|
|
|
ScalarType,
|
2015-07-17 07:37:45 +08:00
|
|
|
StackObject,
|
|
|
|
FixedStackObject,
|
2015-06-27 06:56:48 +08:00
|
|
|
NamedGlobalValue,
|
|
|
|
GlobalValue,
|
2015-07-22 00:59:53 +08:00
|
|
|
ExternalSymbol,
|
2015-06-24 07:42:28 +08:00
|
|
|
|
|
|
|
// Other tokens
|
2015-07-11 06:51:20 +08:00
|
|
|
IntegerLiteral,
|
2015-08-01 04:49:21 +08:00
|
|
|
FloatingPointLiteral,
|
2016-10-13 05:06:45 +08:00
|
|
|
HexLiteral,
|
2015-07-16 07:38:35 +08:00
|
|
|
VirtualRegister,
|
2015-07-21 04:51:18 +08:00
|
|
|
ConstantPoolItem,
|
2015-07-28 06:42:41 +08:00
|
|
|
JumpTableIndex,
|
2015-07-29 01:28:03 +08:00
|
|
|
NamedIRBlock,
|
2015-07-28 06:42:41 +08:00
|
|
|
IRBlock,
|
2015-08-04 07:08:19 +08:00
|
|
|
NamedIRValue,
|
2015-08-22 05:54:12 +08:00
|
|
|
IRValue,
|
2016-03-29 02:18:46 +08:00
|
|
|
QuotedIRValue, // `<constant value>`
|
2017-07-12 06:23:00 +08:00
|
|
|
SubRegisterIndex,
|
|
|
|
StringConstant
|
2015-06-23 04:37:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2017-09-28 07:26:01 +08:00
|
|
|
TokenKind Kind = Error;
|
2015-06-23 04:37:46 +08:00
|
|
|
StringRef Range;
|
2015-08-07 07:17:42 +08:00
|
|
|
StringRef StringValue;
|
|
|
|
std::string StringValueStorage;
|
2015-06-24 07:42:28 +08:00
|
|
|
APSInt IntVal;
|
2015-06-23 04:37:46 +08:00
|
|
|
|
|
|
|
public:
|
2017-09-28 07:26:01 +08:00
|
|
|
MIToken() = default;
|
2015-08-06 01:35:55 +08:00
|
|
|
|
2015-08-07 07:17:42 +08:00
|
|
|
MIToken &reset(TokenKind Kind, StringRef Range);
|
2015-06-23 04:37:46 +08:00
|
|
|
|
2015-08-07 07:17:42 +08:00
|
|
|
MIToken &setStringValue(StringRef StrVal);
|
|
|
|
MIToken &setOwnedStringValue(std::string StrVal);
|
|
|
|
MIToken &setIntegerValue(APSInt IntVal);
|
2015-06-24 07:42:28 +08:00
|
|
|
|
2015-06-23 04:37:46 +08:00
|
|
|
TokenKind kind() const { return Kind; }
|
|
|
|
|
|
|
|
bool isError() const { return Kind == Error; }
|
|
|
|
|
2015-08-14 07:10:16 +08:00
|
|
|
bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
|
|
|
|
|
|
|
|
bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
|
|
|
|
|
2015-06-25 01:34:58 +08:00
|
|
|
bool isRegister() const {
|
2015-07-11 06:51:20 +08:00
|
|
|
return Kind == NamedRegister || Kind == underscore ||
|
|
|
|
Kind == VirtualRegister;
|
2015-06-25 01:34:58 +08:00
|
|
|
}
|
2015-06-24 00:35:26 +08:00
|
|
|
|
2015-07-07 07:07:26 +08:00
|
|
|
bool isRegisterFlag() const {
|
2015-07-09 05:23:34 +08:00
|
|
|
return Kind == kw_implicit || Kind == kw_implicit_define ||
|
2015-08-20 02:55:47 +08:00
|
|
|
Kind == kw_def || Kind == kw_dead || Kind == kw_killed ||
|
|
|
|
Kind == kw_undef || Kind == kw_internal ||
|
|
|
|
Kind == kw_early_clobber || Kind == kw_debug_use;
|
2015-07-07 07:07:26 +08:00
|
|
|
}
|
|
|
|
|
2015-08-07 00:49:30 +08:00
|
|
|
bool isMemoryOperandFlag() const {
|
2015-08-07 00:55:53 +08:00
|
|
|
return Kind == kw_volatile || Kind == kw_non_temporal ||
|
2017-07-13 10:28:54 +08:00
|
|
|
Kind == kw_dereferenceable || Kind == kw_invariant ||
|
|
|
|
Kind == StringConstant;
|
2015-08-07 00:49:30 +08:00
|
|
|
}
|
2015-08-04 08:24:45 +08:00
|
|
|
|
2015-06-23 04:37:46 +08:00
|
|
|
bool is(TokenKind K) const { return Kind == K; }
|
|
|
|
|
|
|
|
bool isNot(TokenKind K) const { return Kind != K; }
|
|
|
|
|
|
|
|
StringRef::iterator location() const { return Range.begin(); }
|
|
|
|
|
2015-08-07 07:17:42 +08:00
|
|
|
StringRef range() const { return Range; }
|
2015-07-21 04:31:01 +08:00
|
|
|
|
2015-08-06 01:35:55 +08:00
|
|
|
/// Return the token's string value.
|
2015-08-07 07:17:42 +08:00
|
|
|
StringRef stringValue() const { return StringValue; }
|
2015-07-21 04:31:01 +08:00
|
|
|
|
2015-06-24 07:42:28 +08:00
|
|
|
const APSInt &integerValue() const { return IntVal; }
|
2015-06-27 00:46:11 +08:00
|
|
|
|
|
|
|
bool hasIntegerValue() const {
|
2015-06-27 06:56:48 +08:00
|
|
|
return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
|
2015-08-14 07:10:16 +08:00
|
|
|
Kind == MachineBasicBlockLabel || Kind == StackObject ||
|
|
|
|
Kind == FixedStackObject || Kind == GlobalValue ||
|
|
|
|
Kind == VirtualRegister || Kind == ConstantPoolItem ||
|
2015-08-20 07:31:05 +08:00
|
|
|
Kind == JumpTableIndex || Kind == IRBlock || Kind == IRValue;
|
2015-06-27 00:46:11 +08:00
|
|
|
}
|
2015-06-23 04:37:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Consume a single machine instruction token in the given source and return
|
|
|
|
/// the remaining source string.
|
|
|
|
StringRef lexMIToken(
|
|
|
|
StringRef Source, MIToken &Token,
|
|
|
|
function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
2017-09-28 07:26:01 +08:00
|
|
|
#endif // LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
|