5 changes: 5 additions & 0 deletions llvm/lib/Target/ARM/ARMSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ ARMSubtarget::ARMSubtarget(const Triple &TT, const std::string &CPU,
: (ARMBaseInstrInfo *)new Thumb2InstrInfo(*this)),
TLInfo(TM, *this) {}

bool ARMSubtarget::isXRaySupported() const {
// We don't currently suppport Thumb, but Windows requires Thumb.
return hasV6Ops() && hasARMOps() && !isTargetWindows();
}

void ARMSubtarget::initializeEnvironment() {
// MCAsmInfo isn't always present (e.g. in opt) so we can't initialize this
// directly from it, but we can try to make sure they're consistent when both
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/ARM/ARMSubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ class ARMSubtarget : public ARMGenSubtargetInfo {
}
bool isTargetAndroid() const { return TargetTriple.isAndroid(); }

virtual bool isXRaySupported() const override;

bool isAPCS_ABI() const;
bool isAAPCS_ABI() const;
bool isAAPCS16_ABI() const;
Expand Down
23 changes: 0 additions & 23 deletions llvm/lib/Target/X86/X86AsmPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,6 @@ class LLVM_LIBRARY_VISIBILITY X86AsmPrinter : public AsmPrinter {

StackMapShadowTracker SMShadowTracker;

// This describes the kind of sled we're storing in the XRay table.
enum class SledKind : uint8_t {
FUNCTION_ENTER = 0,
FUNCTION_EXIT = 1,
TAIL_CALL = 2,
};

// The table will contain these structs that point to the sled, the function
// containing the sled, and what kind of sled (and whether they should always
// be instrumented).
struct XRayFunctionEntry {
const MCSymbol *Sled;
const MCSymbol *Function;
SledKind Kind;
bool AlwaysInstrument;
const class Function *Fn;
};

// All the sleds to be emitted.
std::vector<XRayFunctionEntry> Sleds;

// All instructions emitted by the X86AsmPrinter should use this helper
// method.
//
Expand All @@ -117,8 +96,6 @@ class LLVM_LIBRARY_VISIBILITY X86AsmPrinter : public AsmPrinter {
// function.
void EmitXRayTable();

// Helper function to record a given XRay sled.
void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind);
public:
explicit X86AsmPrinter(TargetMachine &TM,
std::unique_ptr<MCStreamer> Streamer)
Expand Down
10 changes: 0 additions & 10 deletions llvm/lib/Target/X86/X86MCInstLower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,16 +1020,6 @@ void X86AsmPrinter::LowerPATCHPOINT(const MachineInstr &MI,
getSubtargetInfo());
}

void X86AsmPrinter::recordSled(MCSymbol *Sled, const MachineInstr &MI,
SledKind Kind) {
auto Fn = MI.getParent()->getParent()->getFunction();
auto Attr = Fn->getFnAttribute("function-instrument");
bool AlwaysInstrument =
Attr.isStringAttribute() && Attr.getValueAsString() == "xray-always";
Sleds.emplace_back(
XRayFunctionEntry{Sled, CurrentFnSym, Kind, AlwaysInstrument, Fn});
}

void X86AsmPrinter::LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI,
X86MCInstLower &MCIL) {
// We want to emit the following pattern:
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/X86/X86Subtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ class X86Subtarget final : public X86GenSubtargetInfo {
bool hasPKU() const { return HasPKU; }
bool hasMPX() const { return HasMPX; }

virtual bool isXRaySupported() const override { return is64Bit(); }

bool isAtom() const { return X86ProcFamily == IntelAtom; }
bool isSLM() const { return X86ProcFamily == IntelSLM; }
bool useSoftFloat() const { return UseSoftFloat; }
Expand Down
24 changes: 24 additions & 0 deletions llvm/test/CodeGen/ARM/xray-armv6-attribute-instrumentation.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; RUN: llc -filetype=asm -o - -mtriple=armv6-unknown-linux-gnu < %s | FileCheck %s

define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
; CHECK-LABEL: Lxray_sled_0:
; CHECK-NEXT: b #20
; CHECK-NEXT: mov r0, r0
; CHECK-NEXT: mov r0, r0
; CHECK-NEXT: mov r0, r0
; CHECK-NEXT: mov r0, r0
; CHECK-NEXT: mov r0, r0
; CHECK-NEXT: mov r0, r0
; CHECK-LABEL: Ltmp0:
ret i32 0
; CHECK-LABEL: Lxray_sled_1:
; CHECK-NEXT: b #20
; CHECK-NEXT: mov r0, r0
; CHECK-NEXT: mov r0, r0
; CHECK-NEXT: mov r0, r0
; CHECK-NEXT: mov r0, r0
; CHECK-NEXT: mov r0, r0
; CHECK-NEXT: mov r0, r0
; CHECK-LABEL: Ltmp1:
; CHECK-NEXT: bx lr
}
24 changes: 24 additions & 0 deletions llvm/test/CodeGen/ARM/xray-armv7-attribute-instrumentation.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; RUN: llc -filetype=asm -o - -mtriple=armv7-unknown-linux-gnu < %s | FileCheck %s

define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
; CHECK-LABEL: Lxray_sled_0:
; CHECK-NEXT: b #20
; CHECK-NEXT: nop
; CHECK-NEXT: nop
; CHECK-NEXT: nop
; CHECK-NEXT: nop
; CHECK-NEXT: nop
; CHECK-NEXT: nop
; CHECK-LABEL: Ltmp0:
ret i32 0
; CHECK-LABEL: Lxray_sled_1:
; CHECK-NEXT: b #20
; CHECK-NEXT: nop
; CHECK-NEXT: nop
; CHECK-NEXT: nop
; CHECK-NEXT: nop
; CHECK-NEXT: nop
; CHECK-NEXT: nop
; CHECK-LABEL: Ltmp1:
; CHECK-NEXT: bx lr
}