[llvm] r312143 - [codeview] make DbgVariableLocation::extractFromMachineInstruction use Optional
Bob Haarman via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 30 10:50:21 PDT 2017
Author: inglorion
Date: Wed Aug 30 10:50:21 2017
New Revision: 312143
URL: http://llvm.org/viewvc/llvm-project?rev=312143&view=rev
Log:
[codeview] make DbgVariableLocation::extractFromMachineInstruction use Optional
Summary:
DbgVariableLocation::extractFromMachineInstruction originally
returned a boolean indicating success. This change makes it return
an Optional<DbgVariableLocation> so we cannot try to access the fields
of the struct if they aren't valid.
Reviewers: aprantl, rnk, zturner
Subscribers: llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D37279
Modified:
llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=312143&r1=312142&r2=312143&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Wed Aug 30 10:50:21 2017
@@ -960,11 +960,9 @@ void CodeViewDebug::calculateRanges(
assert(DVInst->isDebugValue() && "Invalid History entry");
// FIXME: Find a way to represent constant variables, since they are
// relatively common.
- DbgVariableLocation Location;
- bool Supported =
- DbgVariableLocation::extractFromMachineInstruction(Location, *DVInst);
- // If not Supported, don't even look at Location because it's invalid.
- if (!Supported)
+ Optional<DbgVariableLocation> Location =
+ DbgVariableLocation::extractFromMachineInstruction(*DVInst);
+ if (!Location)
continue;
// Because we cannot express DW_OP_deref in CodeView directly,
@@ -975,13 +973,13 @@ void CodeViewDebug::calculateRanges(
// we need to remove a level of indirection from incoming locations.
// E.g. [RSP+8] with DW_OP_deref becomes [RSP+8],
// and [RCX+0] without DW_OP_deref becomes RCX.
- if (!Location.Deref) {
- if (Location.InMemory)
- Location.InMemory = false;
+ if (!Location->Deref) {
+ if (Location->InMemory)
+ Location->InMemory = false;
else
- Supported = false;
+ continue;
}
- } else if (Location.Deref) {
+ } else if (Location->Deref) {
// We've encountered a Deref range when we had not applied the
// reference encoding. Start over using reference encoding.
Var.Deref = true;
@@ -991,19 +989,18 @@ void CodeViewDebug::calculateRanges(
}
// If we don't know how to handle this range, skip past it.
- if (!Supported || Location.Register == 0 ||
- (Location.Offset && !Location.InMemory))
+ if (Location->Register == 0 || (Location->Offset && !Location->InMemory))
continue;
// Handle the two cases we can handle: indirect in memory and in register.
{
LocalVarDefRange DR;
- DR.CVRegister = TRI->getCodeViewRegNum(Location.Register);
- DR.InMemory = Location.InMemory;
- DR.DataOffset = Location.Offset;
- if (Location.FragmentInfo) {
+ DR.CVRegister = TRI->getCodeViewRegNum(Location->Register);
+ DR.InMemory = Location->InMemory;
+ DR.DataOffset = Location->Offset;
+ if (Location->FragmentInfo) {
DR.IsSubfield = true;
- DR.StructOffset = Location.FragmentInfo->OffsetInBits / 8;
+ DR.StructOffset = Location->FragmentInfo->OffsetInBits / 8;
} else {
DR.IsSubfield = false;
DR.StructOffset = 0;
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp?rev=312143&r1=312142&r2=312143&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp Wed Aug 30 10:50:21 2017
@@ -13,6 +13,8 @@
//===----------------------------------------------------------------------===//
#include "DebugHandlerBase.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
@@ -23,12 +25,14 @@
using namespace llvm;
-bool DbgVariableLocation::extractFromMachineInstruction(
- DbgVariableLocation &Location, const MachineInstr &Instruction) {
+Optional<DbgVariableLocation>
+DbgVariableLocation::extractFromMachineInstruction(
+ const MachineInstr &Instruction) {
+ DbgVariableLocation Location;
if (!Instruction.isDebugValue())
- return false;
+ return None;
if (!Instruction.getOperand(0).isReg())
- return false;
+ return None;
Location.Register = Instruction.getOperand(0).getReg();
Location.InMemory = Instruction.getOperand(1).isImm();
Location.Deref = false;
@@ -66,13 +70,13 @@ bool DbgVariableLocation::extractFromMac
Location.Deref = true;
break;
default:
- return false;
+ return None;
}
++Op;
}
Location.Offset = Offset;
- return true;
+ return Location;
}
DebugHandlerBase::DebugHandlerBase(AsmPrinter *A) : Asm(A), MMI(Asm->MMI) {}
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h?rev=312143&r1=312142&r2=312143&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h Wed Aug 30 10:50:21 2017
@@ -47,12 +47,13 @@ struct DbgVariableLocation {
/// Present if the location is part of a larger variable.
llvm::Optional<llvm::DIExpression::FragmentInfo> FragmentInfo;
- /// Extract a VariableLocation from a MachineInstr. The struct passed in as
- /// Location is populated. The MachineInstr must be a debug value
- /// instruction.
- /// @return true if successful and false if not.
- static bool extractFromMachineInstruction(DbgVariableLocation &Location,
- const MachineInstr &Instruction);
+ /// Extract a VariableLocation from a MachineInstr.
+ /// This will only work if Instruction is a debug value instruction
+ /// and the associated DIExpression is in one of the supported forms.
+ /// If these requirements are not met, the returned Optional will not
+ /// have a value.
+ static Optional<DbgVariableLocation>
+ extractFromMachineInstruction(const MachineInstr &Instruction);
};
/// Base class for debug information backends. Common functionality related to
More information about the llvm-commits
mailing list